Sunday, October 31, 2010

Re: About widgets management



On Thu, Oct 28, 2010 at 6:55 AM, Pablo G.F <blayhck@gmail.com> wrote:
But when I create the menu I have to write the behaviour of each
widget (when hide/show etc), so I have to instance them. I know what
you mean by using Singleton but with that approach I can specify the
behaviour, because they're not created yet.

No, you don't have to instantiate them every time to accomplish what you need to do. Singletons are capable of handling these situations. All that it requires is that you add static methods to your class for what ever behavior you want to exercise on the widget. To show the widget all you would then need to do would be to call YourWidgetClass.getInstance().show() and to hide it YourWidgetClass.getInstance().hide().

In essence you are providing a static api via encapsulation and each static method's implementation does the actual work of manipulating the widget. For example, YourWidgetClass.getInstance().show() would be implemented as follows:

 public static void show(){
    instance.show();
}


What I want is a way to create a menu with widgets associated to it
and work like a standard web app with html pages, showing the widget
requested in the menu and hiding the other ones. But the problem is
that I´d like not having to instance all widgets at the beggining, but
I don´t see any other way to give them the correct behaviour.

Singleton do not require you instance them when your app starts. They will be instanced when you call their their static factory method .getInstance() and only then. Also, remember that on your client the code running is Javascript which performs garbage collection. At any point you can 'delete' the singletons by calling their api methods to handle deletion from the dom and then follow up with calling the widget's apis that do any further cleaning up. Just remember to set instance to null when you do so that your next call to YourWidgetClass.getInstance()  wont fail.

Any other help?

Thx

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.




--
Jeff

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment