Tuesday, May 15, 2012

Re: Advice using activities/places in MVP with some self-contained widgets

I think your original hunch was correct. I like using a presenter or
"delegate" pattern. Choose an activity to control your widget. If your
widget is part of a view, that view should have a corresponding
activity and that should be the thing that controls your widget and
fires events on its behalf. Since your widget is the one that has
special needs, it should define what it needs. In the widget class
define an interface

public interface MyWidgetDelegate {
public void doMyThing();
}

Add a method to your widget class:
public void setDelegate(MyWidgetDelegate delegate) {
this.delegate = delegate;
}

Now your activity implements MyWidgetDelegate and the activity is
responsible for calling setDelegate(this);

Now whenever your widget needs it can call delegate.doMyThing() which
the activity implements and can be responsible for interacting with
the eventbus or doing any other smart thing.

I use this pattern all over the place and I think it's the cleanest
way to deal with this problem.

--
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.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate