2

I have read a lot of gwt-mvp questions that are asked here, but since i'm totally new to this design pattern I would like to ask some questions:

[1] The Activity-Place pattern is a different pattern than mvp?

[2] In the MVP pattern presenters contain the logic. Now the logic of the widgets/controls is defined in the Activities?

[3] The CustomPlace classes are fixed (as the Eclipse plugin constructs them) or can i put data/methods and what kind?

[4] What is the use of the Presenter interface inside a CustomView? What data/methods would make sense to add into it?

[5] I want to build an application that will use many data structures that will be saved into a database. I have read some other posts here and I will make the Model part of MVP live inside each Activity. So i think to create each time the data structures of each activity at start and load its values (if necessary from db) and will update the database after the user goes to another view. What do you think about this approach?

Fotinopoulos Giorgos
  • 1,027
  • 3
  • 17
  • 36

2 Answers2

3
  1. Let's start by debunking one myth: Activities/Places have nothing to do with MVP. Places is about navigation, Activities are about "componentizing" the UI wrt Places. On the other hand, MVP is a design pattern, it's about how to organize your code.

  2. Many people are using their activities as their MVP-presenters, but it's not enforced. The GWT team is trying a new approach where the activity is distinct from the presenter (work underway in the mobilewebapp sample if you want to follow what's going on there). You could also have your activity being your view and making use of an "internal" presenter (similar to how Cell widgets work)

  3. A Place is more or less a URL. You can put whatever you want in it. I'd suggest making places immutable though: build a Place, goTo it, make use of its properties to build your UI.

  4. That's about MVP then. This is only needed to decouple your view and presenter, mostly to make mocking in unit tests easier (this is particularly of the view interface though, not much for the presenter one, unless writing a test harness for you views). In some cases, you might also want to use the same view with distinct presenters; they'll all implement the same interface so the view can talk back to them.

  5. How about the closing of the window/tab? I'd rather use a periodic auto-save, or an explicit save button; and implement mayStop so it prompts the user when there are unsaved changes (similar to how most desktop office apps work —e.g. MS Word or LibreOffice—, and GMail if you try to navigate away before your mail draft is auto-saved)

Thomas Broyer
  • 64,353
  • 7
  • 91
  • 164
  • wow! two answers (Peter, Thomas) two different explanations. What should i follow? Is Activities/Places an MVP implementation or not? (I know you say it isn't :). So can i use both 'patterns'? Is the mobilewebapp an example of this (where can i find it-i google it with no success) ? In your 5th point you suggest to prompt the user to save the data from the view that he's leaving, right? – Fotinopoulos Giorgos Jul 05 '11 at 22:23
  • mobilewebapp is in the GWT SDK 2.4-beta1, and can be found in GWT's SVN repo. What I suggest in step 5 is to return a non-null value from `mayStop` whenever there's unsaved data; Activities&Places will do the rest to prompt the user and eventually cancel the navigation. – Thomas Broyer Jul 06 '11 at 11:09
2
  1. The Activity-Place is an implementation of the pattern. Google introduced gwt-mvp pattern at Google IO, but only provided it's implementation as part of GWT about a year later.

  2. Yes Activities contain business logic. No, widgets/controls usually do not contain any logic, they just fire events based on user action. The logic that acts upon those events is written by user and resides elsewhere.

  3. I don't use Eclipse, so wouldn't know about Places generated by it. Normally custom Places can contain custom fields and methods. For example they can contain custom place token arguments, i.e. if place token is "#place:id1", than your custom Place could contain field holding this argument.

  4. When View needs to call/access Activity, it does so via Presenter, which Activity implements. For example when user enters all data in a for and presses submit, then you could have a method in Presenter named submit(formData).

  5. Preparing/loading data in activity.start(..) is a normal way of doing things. If particular activity is used a lot, then you might consider caching the data if appropriate.

Peter Knego
  • 79,991
  • 11
  • 123
  • 154
  • regarding the 4th answer, if i have a rpc service that is associated with a control in a view, then is it logical (according to pattern) to add it into the ClientFactory and then declare a method in corresponding presenter, implement it inside an activity and use it in view? Also can be an activity without a view or vice versa and what for? – Fotinopoulos Giorgos Jul 05 '11 at 21:59
  • Yes, thats how I'd use rpc (except that I usually use GIN). Activity represents something user does, and if there is no View, then user could not do it. Basically Activities actions are triggered via View. – Peter Knego Jul 05 '11 at 22:20