"Framework" MVC, MVP, MVVM use relationship Summary

Source: Internet
Author: User

MVC

The full name of MVC is the model View Controller, which is the abbreviation for the models-view-controller, a software design paradigm that organizes the code with a method of business logic, data, and interface display separation. Aggregating business logic into a single component does not require rewriting business logic while improving and personalizing the interface and user interaction. MVC is uniquely developed to map the traditional input, processing, and output functions in a logical graphical user interface structure.

Data Relations
    • View accepts user interaction requests
    • View transfers the request to the controller
    • Controller operation model for data update
    • Model notifies view update data changes after data update
    • View Update change data
Way

All methods are one-way communication

Structure Implementation

View: Using composite mode
View and controller: using strategy mode
Model and View: Synchronizing information using observer mode

Use

The view in MVC can be accessed directly from 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.

MVP

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.

Data Relations
    • View receives user interaction requests
    • View transfers the request to Presenter
    • Presenter operation model for data update
    • Model Notification presenter data changed
    • Presenter Update View data
the MVP Advantage
    1. Model and view are completely separated, and the changes do not affect each other
    2. Use more efficiently, because all of the logical interactions occur in one place-presenter internal
    3. A preseter can be used for multiple view without the need to change the logic of presenter (because view changes are always more frequent than model).
    4. More convenient to test. By putting logic in the presenter, you can test the logic out of the user interface (unit test)
Way

Two-way communication between the parts

Structure Implementation

View: Using composite mode
View and presenter: Using Mediator mode
Model and presenter: synchronizing information with Command mode

MVC and MVP differences

One of the biggest differences between MVP and MVC is that there should be no communication between model and view layer (even two-way communication)

MVC and MVP relationships
MVP:是MVC模式的变种。项目开发中,UI是容易变化的,且是多样的,一样的数据会有N种显示方式;业务逻辑也是比较容易变化的。为了使得应用具有较大的弹性,我们期望将UI、逻辑(UI的逻辑和业务逻辑)和数据隔离开来,而MVP是一个很好的选择。Presenter代替了Controller,它比Controller担当更多的任务,也更加复杂。Presenter处理事件,执行相应的逻辑,这些逻辑映射到Model操作Model。那些处理UI如何工作的代码基本上都位于Presenter。MVC中的Model和View使用Observer模式进行沟通;MPV中的Presenter和View则使用Mediator模式进行通信;Presenter操作Model则使用Command模式来进行。基本设计和MVC相同:Model存储数据,View对Model的表现,Presenter协调两者之间的通信。在 MVP 中 View 接收到事件,然后会将它们传递到 Presenter, 如何具体处理这些事件,将由Presenter来完成。如果要实现的UI比较复杂,而且相关的显示逻辑还跟Model有关系,就可以在View和 Presenter之间放置一个Adapter。由这个 Adapter来访问Model和View,避免两者之间的关联。而同时,因为Adapter实现了View的接口,从而可以保证与Presenter之 间接口的不变。这样就可以保证View和Presenter之间接口的简洁,又不失去UI的灵活性。
Use

The implementation of the MVP is somewhat different depending on the implementation of the view, some of which tend to place simple logic in the view, place complex logic in the presenter, and tend to place all the logic in the presenter. These two distinctions are known as: Passive View and Superivising Controller.

MVVM

MVVM is shorthand for Model-view-viewmodel. Microsoft's WPF brings new technical experiences, such as Silverlight, audio, video, 3D, animation ..., which leads to a more detailed and customizable software UI layer. At the same time, at the technical level, WPF brings new features such as binding, Dependency property, Routed Events, Command, DataTemplate, ControlTemplate, and more. The origin of the MVVM (Model-view-viewmodel) framework is a new architectural framework that evolves when the MVP (Model-view-presenter) pattern is applied in conjunction with WPF. It is based on the original MVP framework and incorporates the new features of WPF to address the increasingly complex needs of our customers.

Data Relations
    • View receives user interaction requests
    • View transfers the request to ViewModel
    • ViewModel Operation Model Data Update
    • Model Update data, notify ViewModel data changes
    • ViewModel Update View data
Way

Two-way binding. View/model changes are automatically reflected in the ViewModel, and vice versa.

Use
    • Can be compatible with the MVC/MVP framework you use today.
    • Increase the testability of your application.
    • Working with a binding mechanism works best.
MVVM Benefits

The MVVM pattern, like the MVC pattern, is primarily designed to separate views and models, with several advantages:
1. Low coupling. View can be independent of the model changes and modifications, a viewmodel can be bound to different "view", when the view changes when the model can be unchanged, when the model changes when the view can be unchanged.
2. reusability. You can put some view logic in a viewmodel and let many views reuse this view logic.
3. Independent development. Developers can focus on business logic and Data Development (ViewModel), where designers can focus on page design and generate XML code.
4. can be tested. The interface is always more difficult to test, and now the test can be written for ViewModel.

evolution of the three MVC,MVP,MVVM

Description

Any project framework is service to the project. There is no absolute good or bad points, only the more appropriate choice. Making the most appropriate adjustments at different stages of the project is a better framework for team project development. Project designers should keep in mind that any project design is based on the project development phase, team members size, and team overall ability. Do not design for the design, for the framework of the framework. The most appropriate architecture is to quickly and efficiently match the overall team progress project. Is the only way for a programmer to become a leader and an architect.

Reproduced, please indicate source: http://blog.csdn.net/hudan2714/article/details/50990359

"Framework" MVC, MVP, MVVM use relationship Summary

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.