I long time ago I opened an issue about the Composite widget:
http://code.google.com/p/google-web-toolkit/issues/detail?id=2508

I think the Composite widget should be improved because:
1) Creating all widgets in the constructor is an anti-pattern (evil)
like discussed in for example the book effective programming.
2) It's not lazy loading any widget.

To not get any problems using the Composite widget you should use call
the initWidget() method in the constructor, meaning that you have to
create your widget in the constructor
Something like this:
public MyWidget() {

  initWidget(createMyWidget());
}

In case the method createMyWidget() call several other Composite
widgets, this can be "slow" operation without that you realize it as
you don't really know that the called composite widgets do. I think
you only want to create all these widgets when it's needed (the lazy
loading idea).

I remember that GWT Designer of Instantiations is also creating all
the widgets directly in the constructor (at least it was about a year
ago)..
I often see this at clients that use gwt designer, that all widgets
are created too early instead of lazily which has an performance
impact.

More advanced gwt developers probably recognize this and have a simple
answer: "use the onAttach/onCreated" method to create all your widgets
and simple call initWidget in the constructor with only the outer
panel, which can be a simple div...
I started like this as well, and then end up creating my own
SimpleComposite that extends Composite and only asks the subclasses to
create the widget when it's needed, as such getting real lazy creation
of the widgets, which I think should be an important goal.

However the gwt beginners, will not start like that and will create
their widgets to early and all in the constructor.

Why not make this kind of lazy-behavior more standard in the current
Composite implementation such that all gwt developers are using it
without even knowing it and no need to think extra about it?

I like to hear your feedback about this and maybe the gwt dev team can
have a look at it (maybe after 2.1 is out).

Thanks,
Ed

-- 
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to