Classic design pattern MVC understanding

MVC is an abbreviation of Model (Model), View (View), and Controller (Controller). It organizes code by separating business logic, data, and display. Just a quick review today.

mvc interpretation understanding

insert image description here

M stands for Model (Model), which means business rule encapsulation. Of the three components of MVC, the model has the most processing tasks. The data returned by the model is neutral, and the model has nothing to do with the data format. Such a model can provide data for multiple views. Since the code applied to the model can be reused by multiple views only once, the duplication of code is reduced. sex.

V stands for View (View), which means the interface that the user sees and interacts with. For example, a web page interface composed of HTML elements, or a client interface of a software. One of the benefits of MVC is that it can handle many different views for an application. No real processing happens in the view, it's just a way of outputting data and allowing the user to manipulate it.

C stands for Controller (Controller), which means accepting user input and calling the model and view to complete the user's needs. The controller itself does not output anything or do any processing. It just receives the request and decides which model component to call to process the request, and then decides which view to use to display the returned data.

Advantage

This design pattern is relatively simple, more suitable for business scenarios that require server-side rendering of pages, and more friendly to SEO.

shortcoming

At present, with the rise of MVVM development mode and the rapid development of front-end technology, especially the emergence of some front-end development frameworks such as Vue, React, Angular and other projects, the use of MVC design mode on the server side has become less and less.

For business scenario projects where the business logic is not particularly complicated, MVC can still do a job with ease, but as the business logic becomes large and complex, the problem of rising project maintenance costs of the MVC design pattern becomes more and more obvious. Especially with the development of the microservice architecture of Internet projects, the MVC design pattern has become more and more tasteless in the development of most Internet projects. The main reasons are as follows:
  1. The further separation of view display and data operation methods, especially the development of mobile terminals and the development of front-end MVVM frameworks, in most of our scenarios no longer requires server-side rendering of View.
   2. MVC's code layered design mode is actually relatively coarse-grained:
Model-level code not only maintains data, but also encapsulates business logic. As business logic becomes more and more complex, the functional logic of this layer will become more and more complicated. The more bloated and difficult to maintain.
  3. For team management, the boundaries of responsibilities between Controller and Model are relatively blurred, and the requirements for developers to write good code will be relatively high. The concept seems simple, but it is difficult to adapt to industrial software production.

Guess you like

Origin blog.csdn.net/weixin_43578304/article/details/129194168