Summary of mvc, mvp, and mvvm usage relationships, mvcmvvm

Source: Internet
Author: User

Summary of mvc, mvp, and mvvm usage relationships, mvcmvvm

MVC

The full name of MVC is Model View Controller, short for model-view-controller. It is a Model of software design, organize Code by means of separation of business logic, data, and interface display, and integrate the business logic into a component to improve and personalize the custom interface and user interaction, you do not need to rewrite the business logic. MVC is uniquely developed to map traditional input, processing, and output functions in a logical graphical user interface structure. (Mvc actual source code download: http://www.jinhusns.com/Products/Download? Type = xcj)

Data Relationship
  • View accepts user interaction requests
  • View transfers the request to the Controller
  • Controller operation Model for data update
  • After the data is updated, the Model notifies the View to update the data changes.
  • View update Change Data
Method

All methods are unidirectional communication.

Structure implementation

View: Composite mode
View and Controller: Use Strategy Mode
Model and View: Synchronize information in Observer Mode

Use

View in MVC can directly access Model! As a result, the View will contain Model information, and some business logic will inevitably be included. In the MVC Model, the Model is not changed, but there are multiple different models and views. Therefore, in the MVC Model, the Model does not depend on the View, but the View depends on the Model. Not only that, because some business logic is implemented in the View, it is difficult to change the View. At least those business logic cannot be reused.

MVP

The mvp is called Model-View-Presenter. The Model provides data, the View is responsible for display, and the Controller/Presenter is responsible for logical processing. There is a major difference between MVPs and MVC: In MVPs, views do not directly use models. Communication between them is implemented through Presenter (Controller in MVC, all interactions occur within the Presenter. In MVC, the View directly reads data from the Model rather than through the Controller.

Data Relationship
  • View receives user interaction requests
  • View transfers the request to the Presenter
  • Presenter operation Model for data update
  • Model notifies the Presenter of data changes.
  • Presenter updates View data
Advantages of MVP Method

Each part is a two-way communication

Structure implementation

View: Composite mode
View and Presenter: Use Mediator Mode
Model and Presenter: Synchronize information in Command mode

Differences between MVC and MVP

One of the biggest differences between MVPs and MVC is that the Model and View layer should not communicate (or even two-way communication)

Relationship between MVC and MVP
MVP: a variant of the MVC pattern. In project development, the UI is easy to change and diverse. There are N display methods for the same data, and the business logic is easy to change. In order to make the application more elastic, we expect to isolate the UI, logic (UI logic and business logic) from data, and MVP is a good choice. Presenter replaces Controller, which is more complex than Controller for more tasks. Presenter processes the event and executes the corresponding logic. These logics are mapped to the Model operation Model. The code that processes how the UI works is basically in the Presenter. The Model and View in MVC communicate with each other in the Observer mode. The Presenter and View in MPV communicate with each other in the Mediator mode. The Model of the Presenter operation uses the Command mode. The basic design is the same as that of MVC: Model stores data, View represents the Model, and Presenter coordinates communication between the two. In MVP, View receives events and passes them to the Presenter. How to deal with these events will be done by the Presenter. If the UI to be implemented is complex and the relevant display logic is related to the Model, you can place an Adapter between the View and Presenter. This Adapter is used to access the Model and View to avoid the association between the two. At the same time, because the Adapter implements the View interface, it can ensure that the interface with the Presenter remains unchanged. This ensures that the interface between View and Presenter is concise without losing the UI flexibility.
Use

MVP implementation varies according to View implementation. Some of them tend to place simple logic in View and complicated logic in Presenter; the other part tends to place all the logic in the presenter. These two types are called Passive View and Superivising Controller respectively.

MVVM

MVVM is short for Model-View-ViewModel. Microsoft's WPF brings new technical experiences, such as Silverlight, audio, video, 3D, animation ......, This makes the software UI Layer more detailed and customizable. At the technical level, WPF also brings new features such as Binding, Dependency Property, Routed Events, Command, DataTemplate, and ControlTemplate. The origin of the MVVM (Model-View-ViewModel) Framework is a new architecture framework that evolved from the combination of the Model-View-Presenter Model and WPF. It is based on the original MVP framework and integrates the new features of WPF to cope with the increasingly complex demands of customers.

Data Relationship
  • View receives user interaction requests
  • View transfers the request to ViewModel
  • ViewModel operation Model data update
  • After the Model is updated, the ViewModel data is changed.
  • ViewModel update View data
Method

Bidirectional binding. Changes in View/Model are automatically reflected in ViewModel, and vice versa.

Use
  • Compatible with the MVC/MVP framework you are currently using.
  • Increase the testability of your application.
  • It works best with a binding mechanism.
Advantages of MVVM

The MVVM mode is the same as the MVC mode. It mainly aims to separate views and models. It has the following advantages:
1. Low coupling. The View can be changed and modified independently of the Model. A ViewModel can be bound to different "views". When the View changes, the Model can remain unchanged, and the View can also remain unchanged when the Model changes.
2. reusability. You can put some view logic in a ViewModel so that many views can reuse this view logic.
3. independent development. Developers can focus on business logic and data development (ViewModel). Designers can focus on page design and generate xml code.
4. testable. The interface has always been difficult to test, but now the test can be written for ViewModel.

Evolution of mvc, mvp, and mvvm

Description

Any project framework serves the project. There is no absolute difference between good and bad, and there is only a more appropriate choice. At different stages of the project progress, the most appropriate adjustment is the framework that is more suitable for the development of the Team Project. Project designers should remember that any project design depends on the project development stage, the size of the team members, and the overall ability of the team. Do not design the framework for the purpose of design. Quick and efficient collaboration with the entire team's Progress Project is the most appropriate architecture. It is the only way for a programmer to become a leader and become an architect.

Reprint, please note Source: http://blog.csdn.net/hudan2714/article/details/50990359

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.