Introduction to MVC

Source: Internet
Author: User

? MVC is the shortname of model-View-controller, which is the models-views-controllers.

? MVC It is a design pattern that divides an application into three core modules: models, views, and controllers, each of which handles its own tasks.

The MVC (model-view-controller) application architecture is used to analyze the characteristics of distributed applications. This abstract structure can help to split the application into logical parts, making programming easier.
The MVC architecture provides a way to split various objects by function, which are used to maintain and represent data, in order to minimize the degree of coupling between objects. The MVC structure was originally designed to apply traditional input, processing (processing), and output (outputs) tasks to a graphical user interaction model. However, it is also appropriate to apply these concepts to the Web-based enterprise-level multi-tier application area.

In the MVC structure, the model represents the data of the application and the business rules that govern access to and modification of the data. The model is often used as a software approximation to a process in the real world, and when a model is defined, simple modeling techniques can be used.

When the model changes, it notifies the view and provides the ability to query the relevant state of the model for viewing. It also provides the controller with the ability to access application functionality encapsulated within the model.

A view is used to organize the contents of a model. It obtains data from the model and specifies how the data behaves. When the model changes, it is responsible for maintaining the consistency of the data performance. The controller is also informed of the user requirements.

The controller defines the behavior of the application, and it is responsible for interpreting the user requirements from the view and mapping the requirements to the appropriate behavior, which is implemented by the model. In a standalone GUI client, user requirements may be a few mouse clicks or menu selection actions. In a Web application, they may be represented by a GET or post HTTP request from the client. The behavior that the model implements involves processing the business and modifying the state of the model. Depending on the user requirements and the results of the model behavior, the controller chooses a view as a response to the user request. Typically a set of related feature sets corresponds to a controller.

The process of MVC:

? The controller first receives the user's request and decides which model should be called for processing.

? The model then processes the business logic according to the user request and returns the data.

? The last controller calls the corresponding view to format the data returned by the model and renders it to the user through the view.

Advantages of MVC:

? First, the most important point is that multiple views can share a model. The same model can be reused by different views, which greatly improves the reusability of the code.

? Since the three modules of MVC are independent of each other, changing one does not affect the other two, so a good loosely coupled component can be constructed based on this design idea.

? In addition, the controller improves the flexibility and configuration of the application. The controller can be used to join different models and views to complete the user's needs, so that the controller can provide a powerful means of constructing the application.

MVC's Scope of application:

? Using MVC requires careful planning, because its internal principles are complex, so you need to spend some time understanding it. Applying MVC to your application brings additional effort and adds complexity to your application.

? But for large applications that have a large number of user interfaces and complex business logic, MVC will give your software a new level of robustness, code reuse, and structure. Although it will take a certain amount of effort to initially build the MVC framework, it will greatly improve the efficiency of later software development in the long run.

Introduction to MVC

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.