best/good practices to keep Model in sync with Activity/Place and a view.

74 views
Skip to first unread message

tanteanni

unread,
Apr 24, 2012, 11:20:34 AM4/24/12
to google-we...@googlegroups.com
Since approximately one year i am coding with gwt and MVP pattern (also using "Activity" and "Places") . The VP-Part was never a big Problem. But i often stumbled over getting a "model" for current place or generally how to get from Place  to Model->Activity->View.
My main problem is that on start of an activity the model is mapped into a String (token of a place) and must be "resolved" to data objects (i.e. userId to userObject) . i think that is the main difference between "classic" MVP using an EventBus or other means to communicate state changes (via "real" objects) and A&P-based MVP that knows only two states: the current place.getWhere() and the next goTo(new Place) - each mapped to/from String mapped.
So whats the point: So far i tried many approaches to "resolve" the state, but all feels wrong:
The simplest is to  let the activity resolve the state by calling the needed async-services (to get an user for an userId). But as soon as two activity share the same place/model this code must be copied - bad. The other stuff i tried was even worse - my last attempt (also asked here) didn't work.

My question is: What is best/good practice to implement such a state resolver classes? Are there any examples (Place->Model->Place)?

Jens

unread,
Apr 24, 2012, 2:26:41 PM4/24/12
to google-we...@googlegroups.com
Do you have a concrete example? So far I never stumbled upon a case where I was thinking "hmm thats the same as in the other activity".
In general two activities should do two different things, so if I have for example an userId inside my place then the first activity would maybe fetch the User model class to display general user information (not needed relations would be null) and the second activity would fetch something different based on the userId.

-- J.

tanteanni

unread,
Apr 25, 2012, 2:07:00 AM4/25/12
to google-we...@googlegroups.com
for example a showUserPlace and a EditUserPlace. Or in general there are often more than one usecase per "model". And if i want a distinct url per use case i need different places. This cases could probably solved by let one "userActivity" manage two presenters (edit and show user). But then i have the same issue- how to "inject" the synchronized model from activity in presenter.
But at the moment the problem is not that two activities. Now i have a very complicated logic on the model so i decided to put this logic out of activity/presenter (ui handling logic). here is the same problem how to let the activity interact with a model. (i linked the concrete problem above - for short: if used events i have the problem to register for an event and trigger an event(asking the model) all in start method seem to fail)

Thomas Broyer

unread,
Apr 25, 2012, 4:49:29 AM4/25/12
to google-we...@googlegroups.com

On Wednesday, April 25, 2012 8:07:00 AM UTC+2, tanteanni wrote:
for example a showUserPlace and a EditUserPlace. Or in general there are often more than one usecase per "model". And if i want a distinct url per use case i need different places. This cases could probably solved by let one "userActivity" manage two presenters (edit and show user). But then i have the same issue- how to "inject" the synchronized model from activity in presenter.
But at the moment the problem is not that two activities. Now i have a very complicated logic on the model so i decided to put this logic out of activity/presenter (ui handling logic). here is the same problem how to let the activity interact with a model. (i linked the concrete problem above - for short: if used events i have the problem to register for an event and trigger an event(asking the model) all in start method seem to fail)

For the "data" thing, I think you simply need a "DAO" on the client-side doing some caching.

As for the events, call your getData() in a ScheduledCommand (use either scheduleFinally or scheduleDeferred).

tanteanni

unread,
Apr 25, 2012, 5:06:48 AM4/25/12
to google-we...@googlegroups.com
Thx
The Problem about Scheduled command is that i loose test ability - one main reason i use MVP (want to test the P without GWTTestCase).

But the Question is how to design such DAO's - i guess that's where i am failing at the moment. My current DAO is firing events - not usable in activities start method without ScheduledCommand. But i also have DAO's that uses delegates to signal "data is ready". But how to godd/best integrate/design such DAO's in a gwt/mvp/a&p app? (and probably how to cut/split good services for them?)

Thomas Broyer

unread,
Apr 25, 2012, 5:14:05 AM4/25/12
to google-we...@googlegroups.com


On Wednesday, April 25, 2012 11:06:48 AM UTC+2, tanteanni wrote:
Thx
The Problem about Scheduled command is that i loose test ability - one main reason i use MVP (want to test the P without GWTTestCase).

Not if you inject the Scheduler into your activity (probably a mock one then, or the StubScheduler implementation).

tanteanni

unread,
Apr 25, 2012, 5:26:09 AM4/25/12
to google-we...@googlegroups.com
Thanks - great idea,

so i inject the abstract class "com.google.gwt.core.client.Scheduler". Do i have to bind an instance or provider to it (the provider will call get())?

ok but this is an perfect answer for this thread. The question here is, is it good to connect the model this way? or general how do you connect the model (more than an object delivered by a service) with the presenter?
Reply all
Reply to author
Forward
0 new messages