Home > Common Problem > body text

The difference between MVVM pattern and MVC pattern

Guanhui
Release: 2020-05-30 16:41:22
Original
4951 people have browsed it

The difference between MVVM pattern and MVC pattern

The difference between MVVM mode and MVC mode

1. MVVM mode is derived from MVC mode;

2 , MVVM mode is two-way binding data, while MVC mode is one-way communication;

3. MVVM mode is generally used for front-end development, while MVC mode is used more on the server side.

MVC

The MVC model was originally rooted in server-side Web development, and later became more capable of client-side development. Web development, capable of meeting its complexity and richness.

MVC is the abbreviation of Model-View-Controller, which divides the application into three parts:

  • Model: Model (used to encapsulate the business with the application Logically related data and data processing methods)

  • View: View (rendered page)

  • Controller: Controller (M and V The connector between is used to control the process of the application and the business logic of the page)

MVC features:

MVC pattern It is characterized by separation of concerns, that is, decoupling the data model from the business and presentation logic in the application. In client-side web development, the code is separated and loosely coupled between the model (M-data, operation data) and view (V-HTML element that displays data), making it easier to develop, maintain and test. client application.

1. View sends instructions to Controller;

2. After Controller completes the business logic, it requires Model to change state;

3. Model sends new data to View. Users get feedback.

Advantages of MVC:

  • #Low coupling, separation of view layer and business layer, allowing the view layer code to be changed without recompiling the model and controller code.

  • High reusability

  • Low life cycle cost

  • MVC enables the development and maintenance of user interfaces The technical content is reduced

  • High maintainability, the separation of the view layer and the business logic layer also makes the WEB application easier to maintain and modify

  • Deployment Fast

MVC Disadvantages:

  • Not suitable for small and medium-sized applications, it takes a lot of time to apply MVC Applications that are not very large usually lose more than they gain.

  • The view and the controller are too closely connected. The view and the controller are separated from each other, but they are closely related components. The view does not have a controller, and its application is very limited. , and vice versa, thus preventing their independent reuse.

  • The view has inefficient access to model data. Depending on the model operation interface, the view may need to be called multiple times to obtain enough display data. Unnecessarily frequent access to unchanged data will also harm operational performance.

MVC application:

At the beginning of web app popularity, MVC was applied in java (struts2) and C# (ASP.NET) In server-side applications, and later in client-side applications, based on the MVC pattern, AngularJS came into being.

MVVM

MVVM is the abbreviation of Model-View-ViewModel. Microsoft's WPF (Windows Presentation Foundation - a Windows-based user interface framework launched by Microsoft) brings a new technical experience, making the software UI layer more detailed and customizable. At the same time, at the technical level, WPF also brings new features such as Binding, Dependency Property, Routed Events, Command, DataTemplate, and ControlTemplate. Wait for new features. The MVVM pattern is actually a new architectural pattern that evolved from the application method of combining the MV pattern with WPF. It is based on the original MVP framework and incorporates the new features of WPF to cope with increasingly complex changes in customer needs.

Advantages of MVVM:

The MVVM mode is similar to the MVC mode. The main purpose is to separate the view (View) and the model (Model). There are several advantages:

  • Low coupling, the view (View) can change and modify independently of the model. A ViewModel can be bound to different "Views". When the View changes, the Model can remain unchanged. When the Model changes, View can also remain unchanged.

  • Reusability, you can put some view logic in a ViewModel, so that many views can reuse this view logic.

  • Independent development, developers can focus on business logic and data development (ViewModel), designers can focus on page design, using Expression Blend can easily design the interface and generate xml code .

  • Testable, the interface has always been difficult to test, but now tests can be written for ViewModel.

Recommended tutorial: "PHP Tutorial"

The above is the detailed content of The difference between MVVM pattern and MVC pattern. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template