1

I'm just starting off on my first attempt at the MVP architecture in GWT.

My understanding is that the job of PlaceTokenizer.getPlace(String) is to take the token in the URL after the hash, parse it, and return a Place with the object to which that token refers.

In my application, I have a resource (say, a video), which I tokenize by the video's unique id. Then my getPlace method ought to take this id, and retrieve the video information from the server. Is this the right approach?

As far as how to execute this, the only way that I could figure out would be to have my RemoteService right on the PlaceTokenizer, and make the call right in that getPlace method. Something about this made me hesitate. It seems like the call would be better suited for the Activity or somewhere else.

Is this how it's done? If not, is there a better way?

Ray
  • 4,829
  • 4
  • 28
  • 55

2 Answers2

3

Your Place doesn't need to download the video. It could just contain the video's id.

Your Activity will receive the Place, which has the video id, and now the Activity can do the downloading or whatever heavy lifting you want.

So: Your PlaceTokenizer only needs to know enough to store the video id in the Place. Let the Activity do the work after that. The only function of getPlace is to turn a String into a Place.

It helped me to mentally rename Place to PlaceTag. The place objects really do not represent places - they represent tags or pointers to places. The actual place is represented by, terribly, the Activity.

Riley Lark
  • 20,660
  • 15
  • 80
  • 128
  • I see, this makes a lot more sense. So instead of the `getPlace` transforming the id to a `Resource` (video container), and the `Place` holding the `Resource`, instead the `getPlace` can generate a place and the `Place` can just hold the id. Then do I make the RPC call in the `Activity` constructor, or in the `start` method? – Ray May 28 '11 at 17:26
  • 1
    I use the constructor to inject dependencies like my RPC-making class, app-wide state information, etc. Then the `start` method does the actual calling. Well... actually my `start` method just gets an instance of the appropriate display and an instance of the appropriate presenter and hooks them up, and then the _presenter_ does the RPC calling... but that may be more abstraction than you need. – Riley Lark May 28 '11 at 20:27
  • Awesome, this is starting to make sense now. – Ray May 28 '11 at 21:12
1

if i may help clarifying the place signification a little more. Your place object is a serializable representation of the state of your client. it will help the activity restoring the screen to its former state by containing all the information you need to build it back.