On 23 fév, 16:22, Eugen Paraschiv <[email protected]> wrote:
> I have a question related to widget creation: is it indicated (to use
> deferred binding and have my code base as small as possible) to create
> my widgets via GWT.create() or can I still have the benefits while
> still creating the widgets via the constructor?
> I ask this because of the limitations of GWT.create(), limitations
> such as:
> - no-args constructor
> - no singleton support (I have some of my widgets as singletons, which
> is not possible if I create them using GWT.create())
>
> So, what is the recommended way to instantiate my widgets?
GWT.create() is an "implementation detail" and IMO should be remain an
"implementation detail". If you need deferred binding, use a "helper"
class and instantiate it with GWT.create *from within your widget*;
effectively hiding the details.
It's not as efficient as using deferred binding on the widget
directly, because it involves an additional class (well, it depends,
if well thought out, the compiler might be able to inline most if not
all of your impl class), but it makes your widgets easier to use (you
don't have to worry whether you should call the constructor or use
GWT.create) and maintain (if your implementation change and needs
deferred binding when you previously didn't need it, by using this
pattern, you don't have to change all your instantiation point from
new MyWidget() to GWT.create(MyWidget.class)).
As for the "singleton support", I don't see any difference between
using new MyWidget() and GWT.create(MyWidget.class), or:
private static MyWidget instance;
public static MyWidget getInstance() {
if (instance == null) instance = new MyWidget();
return instance;
}
and
private static MyWidget instance;
public static MyWidget getInstance() {
if (instance == null) instance = GWT.create(MyWidget.class);
return instance;
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---