Talk about v-p interaction in MVP mode

Source: Internet
Author: User

In almost two years, our project team has a few 10 Lai people on top of a project. This is a project based on Microsoft SCSF (Smart client Software Factory), the client is a Melbourne institution. In the first two weeks, I was instructed to work on code review for a module, during which I found some problems and some ideas. However, some ideas may not be very mature enough to guarantee their correctness, and have the opportunity to write a discussion. Today, some ideas about the MVP.

A simple talk about what MVP is.

If from the level relation, the MVP belongs to the presentation layer design pattern. For a UI module, all of its functions are divided into three parts, which are hosted by model, view, and presenter respectively. Model, view, and presenter collaborate to complete the presentation of the initial data and the response to the user's actions, which have their respective division of responsibilities. Model can be regarded as the business logic of the module and the provider of the data, and the view is dedicated to the presentation of the data visualization and the corresponding response of the user interaction events. In general, view implements a corresponding interface; presenter is a common link between model and view.

The MVP has many variants, one of the most commonly used variants being passive view (passive view). For passive View, the relationship between Model, view, and presenter is shown in the following illustration. View and Modell can not directly interact, view through presenter and model deal with. Presenter accepts the view UI request, completes the simple UI processing logic, invokes model for business processing, and invokes view to reflect the corresponding results. View directly relies on presenter, but presenter indirectly relies on view, which directly relies on the interface of view implementations. About the MVP and passive view basic common sense things, is not the focus of this article discussion, to this unclear reader believe can Google a lot of relevant information, so here is more to do introduction.

A summary of the basic features of passive view model

Passive view, as the name suggests, view is passive. So who's the active? The answer is presenter. For presenter's initiative, I personally understand this:

Presenter is the control center of the MVP system, not simply the person who handles the view request;

View is only the user interaction request of the reporting, to respond to user interaction related logic and process, view does not participate in decision-making, the real decision maker is presenter;

The view sends a user interaction request to presenter should use the same tone: "I will now send the user interactive request to you, you look at it, need me when I will help you", should not be like this: "I now handle the user interaction request, I know what to do, but I need your support, Because the implementation of business logic model only trust you ";

For the data bound to view, should not be the view from the presenter "pull" back, should be presenter active "push" to view;

View does not maintain data state as much as it does, because it only implements simple, independent UI operations; presenter is the coordinator of the entire system, which arranges work for view and model according to the logic used to handle interactions.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.