E4: A First Look

I've finally got some cycles to catch up on E4 a bit. The first thing I notice is that in E4, you wind up with a lot of code that looks something like this: (from http://www.vogella.de/articles/EclipseE4/article.html)

public class View1 {
	@Inject
	public View1(Composite parent) {
		Label label = new Label(parent, SWT.NONE);
		label.setText("E4 is new");
		Text text = new Text(parent, SWT.NONE);
		text.setText("and different");
	}
}

The first thing I notice is the dependency injection: there's no explicit dependency on Eclipse anywhere to be seen.

I haven't worked out all the implications of that @Inject annotation, but at first blush this sort of thing would seem to make E4 *much* more testable than previous versions of Eclipse were.

If I'm right, this is pretty huge. It's not exactly a killer feature, but it's very important.

Thoughts?

Discussion

Philipp Kursawe, 2010/02/06 02:03

From the code above I would have no clue what is actually injected. The parent? Is the view injected somewhere? DI is certainly a good thing. But in that case its not obvious what the annotation does.

Lars Vogel, 2010/02/06 12:28

@Philipp In the example the Composite “parent” is injected. In chapter 6 of http://www.vogella.de/articles/EclipseE4/article.html you see examples of parameter injection which make it more explicit.

Hope this helps.

Lars Vogel, 2010/02/06 12:40

@Philipp: I checked http://www.vogella.de/articles/EclipseE4/article.html and it also explains that the composite it injected into the view.

Sven Efftinge, 2010/02/06 13:49

Yes, dependency injection makes code much more testable. Especially in Eclipse-singleton-land :-)

Boris Bokowski, 2010/02/06 14:33

Not only is code like this easier to test, it is also easier to reuse in different contexts (in a dialog or wizard, in a standalone SWT application, etc).

Enter your comment (wiki syntax is allowed):
ZNEGS
blog/e4_a_first_look.txt · Last modified: 2010/02/05 22:23 by djo
Back to top
Creative Commons License Recent changes RSS feed