Talk about the understanding of MVC, MVP, and MVVM

Source: Internet
Author: User

When I came out to work, I maintained an old system that was written using Microsoft's ASP (Active Server Pages). Each page is an ASP file, each ASP file also contains HTML, CSS, Java script, VB script code, put so many code together, you can imagine if a such page contains complex business logic, Every time you want to maintain or add new functionality to the system, that acid is cool.

Such a combination of interfaces, business logic, and data models is highly undesirable in terms of software design and maintainability. In order to solve the above problems, we developed various mv* framework models (mv* theory itself is a model, but its various implementations are called mv* framework), it is to achieve the interface separation by solving the coupling problem between M and V.

    • Mvc:model-view-controller
    • Mvp:model-view-presenter
    • Mvvm:model-view-viewmodel

Summary: It can be seen from the full name above, whether MVC, MVP and MVVM are all around the model and view, is to solve the model and view of the coupling problem, but the realization of the idea is not the same.

Mvc

MVC divides the software system into three basic parts: the model, the view, and the controller, as shown in the relationship:

Model: Database-related operations, access to files, data structures, and so on.

View: Focus on display, such as Web Front end (Html/css/java Script)

Controller: Connect models and views, such as sending a request for a view to a model or returning data to a view, etc.

MVC is just a framework pattern, and there are some differences in how implementations are implemented for different platform environments: WEB MVC

The classic web MVC pattern, implemented with the framework of ASP. NET mvc/spring MVC, and so on, the model data in Web MVC is returned to view through the controller.

Desktop UI MVC

The classic implementation of PUREMVC,PUREMVC is a lightweight application framework built on the MVC pattern. its model and view interaction is achieved through the observer pattern, when the model has changed to notify the view when the model sends the message to the Notification distribution center, and then notifies the distribution center to send the message to the view.

Summarize:

MVC's implementation of the separation of views and models avoids the combination of views and models, when the view changes as long as the business logic does not change the model, but it has a disadvantage because the controller in MVC does not directly update the view, so MVC does not achieve a complete separation of views and models, The view still relies on the model's data (a data structure) to display, which means that the view relies on the model.

Mvp

The MVP is an improvement on MVC's shortcomings, which divides the software system into three basic parts: model, view, and display (Presenter), as shown in the relationship:

Model: Database-related operations, access to files, data structures, and so on.

View: Focus on display, such as Web Front end (Html/css/java Script)

Display (Presenter): Connect models and views, process requests for views, and update views based on models.

Summarize:

The MVP replaces the controller with the display, and the display is able to update the view directly, so the MVP can process the view request and deliver to the model and update the view according to the change of the model, which realizes the complete separation of the view and the model.

MVVM

MVVM is a further development of the MVP, dividing the software system into three basic parts: model, view, and view model (ViewModel), as shown in the relationship:

Model: Database-related operations, access to files, data structures, and so on.

View: Focus on display, such as Web Front end (Html/css/java Script)

View Model (ViewModel): Connect models and views, view models and views are double-closed.

Summarize:

MVVM replaces the display in MVP with a view model, and the view model and view implement two-way binding, and the view model changes when the view changes, and the view changes as the view model changes.

MVC/MVP/MVVM are based on different application requirements and application environment gradually developed, they have their own advantages and disadvantages and applicable environment. For example, in web development, the cost of using MVP or MVVM is enormous because of the fact that network data is a valuable resource at the moment because of the need to cross-network communication.

Reprint Please specify source: http://www.cnblogs.com/keitsi/p/5764785.html

Talk about the understanding of MVC, MVP, and MVVM

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.