Model-programmers compile the functions (Implementing algorithms, etc.) of programs and database experts to manage data and design databases (implementing specific functions ).
2. MVC principles
The idea behind the MVC (Model-View-Controller) architecture mode is very simple. Our applications must differentiate the following responsibilities:
Applications are divided into three main parts, each of which is responsible for different tasks.
3. MVC network applications
Controller(Controller)
The Controller is in charge of user requests (when a user clicks an element on the graphic user interface (GUI) to perform operations, the Controller will receive an http get or POST request ). Its main function is to call and coordinate required resources/objects to execute user requests. Generally, the Controller calls an appropriate model for the task and selects an appropriate view.
Model(Model)
A model is a data rule and data content applied to data. It generally corresponds to objects to be managed by applications. In a software system, everything can be abstracted into a data model that can be processed in a certain way. What are the users, information, and books in the application? They are just a bunch of data that must be processed according to the corresponding rules (the date cannot be a future date, the email has a specific format, and the name length cannot exceed many characters ).
The model provides the Controller with a data expression (such as information, books, and album) corresponding to the user request content ). No matter how we present it to users, this data model will not change. This is why we can choose which view to use to display data at will. The model contains the most important components of our application logic, which are applied to the problem we are dealing. The controller contains the internal organizational logic of the application.
View(View)
The view provides different ways to display model data. It may be a data filling template. There can be multiple views, and the Controller determines which view to use. A network application usually consists of many controllers, models, and views. A controller can be considered as a master controller that receives all user requests and then calls a specific controller to handle different situations.
4. Advantages of MVC
One of the most obvious advantages of MVC is that it clearly separates View display from application logic.
Support for different users and different device types has always been a common problem. For example:
The view obtained for requests from desktops and mobile phones should be different, and the model will return identical data, however, the difference is that the controller selects a View File to display data (we can regard it as a different template ).
In addition to separating the view from the business logic, the separation of MVC also reduces the difficulty of large-scale application design, and the code is more structured, so it is easier to maintain, test, and reuse.
5. MVC application scenarios
The disadvantage of the MVC mode is that it is not easy to fully understand the MVC mode because it is not clearly defined. Using the MVC pattern requires careful planning. Because of its complicated internal principles, it takes some time to think about it. Developing an MVC-mode architecture project will have to spend considerable time considering how to apply the MVC-mode to applications. At the same time, the model and view must be strictly separated, this also makes it difficult to debug the application. Each component must be thoroughly tested before use. In addition, because the MVC mode divides an application into three parts, this means that the same project will contain more files than before.
The MVC pattern is not suitable for small or even medium-sized applications, which brings in additional workload and increases application complexity. However, the current multi-data design framework can directly provide the MVC skeleton for the development of small and medium-sized applications. This problem no longer exists. For large-scale applications with a large number of user interfaces and complex logic, MVC will bring a new step to the software in terms of robustness, code reuse, and structure. Although the initial construction of the MVC Framework requires a certain amount of work, it will greatly improve the efficiency of software development in the long run.