MVC pattern and simple to understand MVVM pattern

I believe these are the two familiar words, and widely used among the various MVC java framework, such as Struts2, SpringMVC, etc., as the B / S architecture development, MVS model is what we need to master.

After mvc step by step evolution has now MVVM pattern, beginning, starting with the front of the evolutionary history also appears how the MVC pattern.

First, the front end of evolution

In 1989, the last century, physicists of CERN Tim Berners-Lee invented HTML (HyperText Markup Language), referred to as HTML, the Internet and the draft in 1993. Since then, the rapid commercialization of the Internet began, the birth of a large number of commercial sites.
The first page is completely static when the browser requests a server, web server will be fixed hardcoded HTML file directly back to the browser display
 
If you want to fight for different users show different pages, the server is not possible to store all the thousands of static resources, so the server will need to compete for different users, different dynamically generated html file. One of the most straightforward idea is to use C, C ++ programming language, which returns the string splicing directly into the browser, this technique is known as CGI: Common Gateway Interface.
 
Obviously, some of the complex web needs, and can not be achieved by splicing in this way, and it has been found that most duplicate HTML code blocks, is constant, varying only partial and user-related data, so there dynamic HTML way: ASP (Microsoft), JSP (SUN), PHP (open source community)
 
Of course, this does not directly say that dynamic HTML, once the browser returns an HTML page, you need to update the content of the page, the only way is to retrieve the page to the server, in 1995, javascript born, be modified by modifying the HTML DOM structure and CSS pages, javascript browser native API DOM node to operate, due to limitations native, consider browser compatibility turned out jQuery
 
In the past 10 years, we have put a lot of traditional server-side code into a browser, thus creating thousands of lines of javascript code, they connect a wide variety of HTML and CSS files, but the lack of formal organization, which is why more and more developers to use javascript framework. For example: angular, react, vue. Browser compatibility is no longer obstruct the front end. The front end of the project increases, maintainability and extensibility, security and other projects has become a major problem. Years ago, to solve browser compatibility issues, there have been many libraries, the most typical is the jquery. But this type of library does not implement into the business logic, so poor maintainability and scalability. In summary two reasons, only the emergence of a class of MVVM pattern framework. For example vue, via two-way data binding, which greatly improved the efficiency of development.
 
Two, MVC
Refers Model - View - Controller shorthand, i.e. Model - View - Controller
M (Model) is used for part of the application processing application logic, typically responsible for accessing data model object in the database, the common data is transmitted from the rear end
V (view) of the application data is displayed, the data is usually created based on the model data
C (controller) is part of the application process the user interaction, typically responsible for rendering the model view data to the view layer which
 
MVC is one-way communication. That is, with the View Model, must be the nexus by Controller. MVC and MVVM distinction is not completely replaced the VM C, ViewModel object exists in the display Controller disengagement business logic, rather than replace Controller, etc., or other business views the operation on the Controller should be implemented. That MVVM is to achieve reuse of business logic components. Because of the time mvc appear relatively early, the front is not so mature, a lot of business logic is implemented in the back end, the front end is not the true sense of the MVC pattern. And we mention MVC again today, is because of the large front end came, the emergence of a framework for MVVM pattern
 
 
Three, MVVM
Refers Model - View -ViewModel shorthand, i.e. the model - view - view Model
 
M and V and which refer to the MVC pattern layer of meaning,
VM is the core of the MVVM pattern, it is the link between Model and View, is the two-way binding, it has two directions, one is the model into view, the forthcoming server returns data into page we have seen, to achieve the way data binding, and second, the view into the model, will soon see page data into back-end data, the way to achieve that DOM event listener, in the framework of MVVM the view and model are not directly communicate. They usually achieved by ViewModel communicate, a ViewModel Observer observer, when the data is changed, this change ViewModel able to listen to the data, and then notifies the corresponding view done automatically updated when the user operates the view, but also can monitor ViewModel to change the view, and then make changes to the notification data, which is actually on the realization of two-way data binding. The View and MVVM ViewModel and can communicate with each other.
 
 
Finally, attach a map of MVC

Guess you like

Origin www.cnblogs.com/LiuFqiang/p/11876550.html