Introduction to MVC

Source: Internet
Author: User

MVC is the short name 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 theIn an MVC structure, the model represents the data of the application and the business rules that govern access to and modification of the data. Usually the model is used as a real-world. a model is a domain-specific form of data representation. For example, we are creating a task List application. You may have aA collection of Task objects, written as list<task>. You might want to keep this data in a database, an XML file, or even from a Web service, but MVC doesn't care so much about where/how to persist (and even what they are). Instead, it focuses specifically on how to display this data and handle interacting with the user. The process of software approximation, when defining a model, you can use the general simple modeling techniques.

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

a view (View) is used to organize the content of the model.The view represents how the data is actually displayed. In our hypothetical task application, a Web page ( inHTML) to display these tasks in a WPF page (in XAML), or as UITableView in an iphone application, is displayed. If a user clicks on a task and deletes it, the view usually triggers an event,or toController(Controller) to make a callback. 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 user requirements are also communicated to the Controller (Controller).

Controller (Controller) defines the behavior of the application, which 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 purpose of the device is to get the data in the model and tell the view to display it. The controller also listens for view events and controls the task from the model when the user selects a task to delete.

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.

because The three modules of MVC are independent of each other, and 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:

Use 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 develop a large number of user interfaces and complex business logic, MVC will make your software a new step in robustness, code reuse, and architecture. 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.