Introduction to MVC Structure

Source: Internet
Author: User
This document is compiled from related J2EE documents.
MVC (Model-View-Controller) Application Program Structure is used to analyze the features of distributed applications. This abstract structure can help split an application into several logical components, making programming easier.

The MVC structure provides a way to split objects by function (these objects are used to maintain and present data ), the goal is to minimize the coupling between objects. The MVC structure was originally designed to apply traditional input, processing, and output tasks to Graphical User Interaction Models. However, applying these concepts to the web-based enterprise-level multi-layer applications is also very suitable.

In the MVC structure, the model represents the data of the application and the business rule used to control access and modify the data ). A model is usually used as a software approximation of a processing process in the real world. when defining a model, a general simple modeling technology can be used.

When the model changes, it notifies the view and provides the ability to query the status of the model. It also provides the controller with the ability to access the application functions encapsulated in the model.

A view is used to organize the content of a model. It obtains data from the model and specifies how the data is presented. When the model changes, data Performance consistency is maintained. Inform the Controller as required ).

The controller defines the behavior of an application. It is responsible for interpreting the user requirements from the view and ing these requirements into the corresponding behavior, which is implemented by the model. In a self-running GUI client, you may require some mouse clicks or menu selection operations. In a web application, they may be expressed in some HTTP requests from the client get or post. The behaviors implemented by the model include processing the business and modifying the model status. Based on user requirements and model behavior results, the Controller selects a view as the response to user requests. Generally, a set of related function sets correspond to a controller. Describes the relationship between model, view, and controller in an MVC application:
 
In the figure, the solid line represents the highly coupled dependency, and the dotted line represents the low-coupling message relationship. The business module does not rely on the user interface, thus isolating the impact of user interface changes on the business program. The user interface is used to collect user input and display the data required by the user. The controller is used to call user requests to the actual business program and send the processing results of the business program back to the user interface; the business program processes specific business operations. At the same time, the business module may actively send messages to the user interface, and the notification interface displays data.

In a specific environment, these factors may change. For example, in web development, because of the nature of Web applications, the user interface runs on the browser, while the interface control and business module run on the browser, therefore, this typical MVC pattern is usually used in Web applications. In addition, in Web applications, there is no server that actively pushes data to the client. Therefore, the dotted line between model and view does not exist. In Windows Forms, controllers and interfaces are often merged. For example, in the document-view mode used in the MFC framework, the document corresponds to the Model in MVC and stores business data, process business logic. View is equivalent to view + controller in MVC. It is responsible for display of user interfaces, collection of user inputs, and jump control of images.

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.