Confusion around the whole GWT MVP vs Activity and Places
Asked Answered
S

4

21

After reading a while and watching Google IO videos, I am still confused on how MVP relates to Activity and Places.

I found a thread posted a while back --> GWT 2.2 MVP vs. GWT 2.1 Activities-Places

"MVP architecture. MVP is the concept, and one of the ways to do it is the places-activities framework"

I also hear "A presenter is analogous to an Activity"

We can gave "Activity and Places without MVP"

We can mix in "Activity and Places with MVP"

"MVP is nothing but how we organize our Project so that we can test and organize code easily"

Then I am trying to figure out stuff like this --> http://code.google.com/p/gwt-platform/

I am really confused. I would want a one stop thread to end all the confusion.

Surtout answered 14/6, 2011 at 5:33 Comment(0)
D
21

TL;DR: Places and Activities are in no way related with MVP.

Places is about navigating into your app: you go from one place to another. And Activities builds on top of Places to help in binding "what you see" with "where you are":

  • when I'm on the home page for SO, the main part shows the list of questions in all topics, the top of the right side shows my favorite tags and helps me setup tag filters, then below is an add, and below the add is a list of recent tags, then a list of recent badges.
  • on this question page, the main part shows the question and its answers, the top of the right side is replaced infos on the question's tags, followed by an add, linked questions and then related questions.

Each one of these "parts" (region) are managed by ActivityManagers that listen to PlaceChangeEvents and ask their associated ActivityMapper which Activity to show in that region.

It's all about navigation.

There's no relationship with MVP (despite what the official docs say). If you use MVP though, you'll likely make you activities "presenters", in control of a "view" (the one the activity will pass back to the AcceptsOneWidget received in argument to its start method). This is not a rule though, and, for instance, Google is experimenting, in the mobilewebapp sample, with decoupling activities and presenters.

Duty answered 14/6, 2011 at 10:41 Comment(5)
"if you use MVP", what do you mean by that exactly? As in if I just separate out model-view-presenters on my own and make them interact to an interface with my own implementations?Surtout
If activities are Presenters, isnt their a relationship? :|Surtout
Re. "if you use MVP": MVP is a pattern, so I meant "you put presentation logic into your activity (i.e. make it a presenter) and your view in another class". Re. your second comment, if I say "views will generally be Composites", does that make Composite related to MVP? Maybe it's clearer if I say MVP and activities are orthogonal concerns (one is a coding pattern, the other is a toolkit/micro-framework about in-app navigation)Duty
There is a relationship between MVP and Activities and Places ! Activities are meant to be Presenters. Google documentation : Strictly speaking, MVP architecture is not concerned with browser history management, but Activities and Places may be used with MVP development as shown in this article. In the following article developers.google.com/web-toolkit/doc/latest/… activities implement the Presenter Interface ...Speaks
Activities play well the role of presenters, but they're not meant to be presenters. What do you think of code.google.com/p/google-web-toolkit/source/detail?r=10185 ?Duty
S
9

MVP stands for Model, View, Presenter, it is a coding pattern. It is just an evolution from the MVC (Model, View, Controller) pattern. See MVC wikipedia page.

The difference between MVP and MVC is that in MVP, the model and the view do not know each other. In MVP your view should be as dumb as possible. All the interactions are handled by the Presenter. It is just a way of organizing your code properly.

Some people have created frameworks to reduce the amount of work to do to organize your code this way. Have a look to different MVPimplementations. It is easy to find them on the web.

MVP makes your code easier to test as you can easily replace your view by an other implementation (usually a Mock) that will fake the behavior or your view. Thus you do not need to run your tests with a browser environment(GWT views are HTML views). So your tests will run faster.

Google documentation says :

The Activities and Places framework allows you to create bookmarkable URLs within your application.

So Activities and Places is much more than just an MVP framework. Nevertheless an Activity is a Presenter.

public interface Activity {

  String mayStop();

  void onCancel();

  void onStop();

  void start(AcceptsOneWidget panel, EventBus eventBus);
}

You can use the Activity interface for your presenters without using Places and other objects from Google. But in that case you should probably code a kind of Activity Manager of your own that will be responsible for starting and stopping your activities. In start and stop you probably want to create your view, add it to the dom, register your event handlers etc. And you will want to destroy all this when you stop.

In some others MVP implementations you can find bind() and unbind() methods that have the same role.

The power of the Activity Place implementation from Google comes from all the objects behind the Place object that will make your activity start or stop and that will handle history.

The Place as other people mentioned above is just a representation of you URL.

There are many objects involved in the Activity Place implementation from google. Here is a schema to help you understand. You will see that the activity is only a small part of the whole thing. You can find some more details on my blog in this article

enter image description here

Speaks answered 8/3, 2013 at 12:57 Comment(0)
F
7

Activities are Presenters. Places are just a wrapper for history token.

The confusion began with Google IO video, where MVP GWT concept was introduced, but no implementation was given. So people started rolling their own. Then google wrote the 2.1 docs where they detailed the concept and only gave some example code to download. Later in 2.2 they introduced their full implementation, Activities et al.

So, if you want to go the MVP route you need to pick your implementation. Activites would be probably best, since it's the official one.

Flue answered 14/6, 2011 at 6:25 Comment(0)
T
0

There are two independent dimensions Design Pattern - No pattern - MVP

Navigation and screen traversal - No navigation - Activities and Places

You may have an application that can follow one of the following

  • No MVP, No Activities and Places
  • Only MVP
  • Only Activities and Places
  • MVP with Activities and Places
Thereabouts answered 11/3, 2015 at 19:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.