Talking about MVC, MVP, MVVM model

In learning vue, react in the process, always see MVVM model, then what is MVVM, I recently saw the data as well as their ideas are summarized below it.

MVVM and similar, as well as MVC, MVP, start with MVC, MVP both start with, understand MVVM face of the back panel.

一、 MVC

M: model, i.e. the model, data encapsulation and data processing method for (Ruan Yifeng teacher explained mainly responsible for the business logic).

V: view, i.e. a view, the user interface.

C: controller, i.e. a controller connected to the view model.

There are two means of communication MVC model:

One is received by the view layer instruction, before being passed to the controller layer, the data layer in the model or lookup data modification, and then finally all the changes to the view rendering layer. as the picture shows:

 Another way is to directly receive instructions through the controller layer, then the same process with the first, i.e., without going through view as the connection layer.

MVC model features : all the business logic and data communications are unidirectional, the application will be decoupled, so that the program easier to develop, test and maintain (i.e., low coupling, high reusability, maintainability). But its shortcomings are obvious, the relationship between the view layer and control layer is too tight, so that its application is very limited, only suitable for large-scale application development.

Two, MVP

P: presenter, i.e. viewer, its function and the same controller is also responsible for connecting the Model view, but it changes the direction of communication.

MVP model features : You can see by the chart, the MVP model, between the view and presenter, presenter and model can be both two-way communication, which is the biggest difference with the MVC model. And MVP model, and the model layer is a layer of view can not communicate directly only communicate through presnter, all business logic deployed inside presnter layer, i.e., layer view more "thin", Presenter layer of Comparative "thick . " On the other hand we can see the view and model and complete separation, we can do without affecting modify the view to the model. Shortcoming MVP model is interactive view layer and presenter layers too closely, once the need to modify the view layer, layers have to follow the presenter changes.

Three, MVVM

Next is the protagonist of this article, MVVM model (ViewModel-ViewModel). Can compare it carefully with the MVP model MVVM model can be found only difference is that communication between the view and presenter / viewmodel layer changed, and this is what we often say that the two-way binding. Data that has changed in the view layer can cause data viewmodel layer follow the changes, and vice versa, this is a great core vue framework - two-way data binding (it use to achieve the publisher - subscriber data hijacking mode and follow-up to open a new chapter will be mainly described two-way data binding).

MVVM model features : the model layer can be independently modified layer view, when a view change layer may not affect the layer model, and can be bound to a different viewmodel top view (showing application scenario for the same set of data to the site different places, when modifying data occurs on a view will indeed affect the whole body, causing other view along with modifications). MVVM model has another feature that can be developed independently, that is responsible for the developer viewmodel layer can focus on developing business logic and data, and responsible developers view layer can focus on the development of the page, independently of each other.

 

Guess you like

Origin www.cnblogs.com/hmchen/p/12630116.html