MVP? (MVP mode)? edit

Source: Internet
Author: User

MVP (MVP mode) editor
MVP is all called Model-view-presenter,model to provide data, view is responsible for display, Controller/presenter is responsible for the processing of logic. There is a big difference between MVP and MVC: In MVP, view does not use model directly, communication between them is done through presenter (Controller in MVC), all interactions occur inside presenter, In MVC, view reads the data directly from the model rather than through the Controller.
Chinese name
MVP
foreign name
Model-view-presenter
communication mode
Presenter
bit      Place
inside the presenter
Directory
  1. 1 MVC and MVP
  2. 2 solving MVC problems
  3. 3 Advantages
  4. 4 Disadvantages
MVC and MVPThe editorial MVP evolved from the classic pattern MVC, where the basic ideas were shared: Controller/presenter was responsible for the processing of the logic, the model provided the data, and the view was responsible for the display. As a new model, there is a significant difference between MVP and MVC: In MVP, view does not use model directly, communication between them is through presenter (Controller in MVC), all interactions occur within presenter, In MVC, view reads data from the direct model rather than through the Controller. In MVC, view is directly accessible to the model! As a result, the view contains the model information and inevitably includes some business logic. In the MVC model, more attention is paid to the constant of the model, while there are several different displays of the model, and the view. So, in the MVC model, models do not depend on view, but view is dependent on model. Not only that, because some business logic is implemented in view, it is difficult to change the view, at least those business logic is not reusable.[1]solving MVC problemsEditor in the MVP, presenter completely separates the model from the view, and the main program logic is implemented in the presenter. Furthermore, presenter is not directly related to the specific view, but interacts through a well-defined interface, allowing the presenter to be kept constant when the view is changed, that is, reuse! Not only that, we can also write Test view, simulate the user's various operations, so as to achieve the test of presenter-without the need to use automated testing tools. We can even test the logic of presenter by writing a mock Object (that is, an interface that implements the model and view, but no concrete content) when the model and view are not finished. In the MVP, the logic of the application is mainly implemented in presenter, where the view is a very thin layer. As a result, a design pattern for presenter first was proposed, which was to design and develop presenter based on user story. In this process, the view is simple enough to display the information clearly. At the back, you can change the view as you want, without any effect on the presenter. If the UI to be implemented is complex, and the associated display logic is related to model, you can place a adapter between the view and the presenter. This adapter to access the model and view to avoid the association between the two. At the same time, because the adapter realizes the interface of the view, it can guarantee the same interface with the presenter. This guarantees the simplicity of the interface between the view and the presenter, without losing the flexibility of the UI. In MVP mode, view should only have a simple Set/get method, the user input and Settings interface display content, in addition to this should not have more content, never allow direct access to model--this is a big difference with MVC.[1]AdvantagesEdit 1, the model and the view completely separate, we can modify the view without affecting model 2, can more efficient use of the model, because all the interaction occurs in a place--presenter internal 3, we can use a presenter for multiple views, Without the need to change the logic of presenter. This feature is very useful because view changes are always more frequent than models. 4. If we put logic in presenter, then we can test the logic out of the user interface (unit test)[1]DisadvantagesEditing because the view is rendered in presenter, the interaction of views and presenter is too frequent. It is also important to understand that if presenter renders the view too much, it often makes it more closely related to a particular view. Once the view needs to be changed, the presenter also needs to be changed. For example, the presenter used to render HTML now also needs to be used for rendering PDFs, so the view is likely to need to be changed.
Source: http://baike.baidu.com/subview/7294/10754979.htm

From for notes (Wiz)

MVP? (MVP mode)? edit

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.