문제

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.

도움이 되었습니까?

해결책

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.

다른 팁

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

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.

As long as you think of them as two patterns of development, it is pretty easy to keep them separated. MVP is a pattern for separation of concerns and Activities and Places is a tool for URL and history management.

Here is a good article to help clear up any confusion, MVP, Activities and Places Confusion

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top