An overview of the MVC architecture pattern

Source: Internet
Author: User

Mvc

MVC Overview:

Model–view–controller (MVC) is a software architectural pattern for implementing user interfaces.

MVC mode (Model-view-controller) is a software architecture model in software engineering, which divides the software system into three basic parts: model, view and controller.

MVC The purpose of the model is to implement a dynamic programming design that simplifies the subsequent modification and expansion of the program, and makes it possible to reuse a part of the program.

    • (Controller controllers)-responsible for forwarding requests and processing requests.

The controller, accepts input and converts it to commands for the model or view.

    • (views view)-graphical interface design for interface designers.

A View can is any output representation of information, such as a chart or a diagram; Multiple views of the same information is possible, such as a bar chart for management and a tabular view for Accou Ntants.

    • (model)-Programmer to write the functions that the program should have (implementation algorithm, etc.), database experts for data Management and database design (can achieve specific functions).

The model, captures the application ' s behavior in terms of its problem domain, independent of the user interface. The model directly manages the application ' s data, logic and rules.

Interactive diagrams in the MVC component

Detailed analysis of the components:

  • Model ( Model ) is used to encapsulate data related to the business logic of the application and how to handle the data . "Model" has the right to direct data access, such as access to the database. "Model" does not depend on "view" and "Controller", that is, the model does not care how it will be displayed or how it is manipulated. However, changes in the data in the model are generally advertised through a refresh mechanism . To implement this mechanism, the views that are used to monitor this model must be registered in advance on this model , so that the view can understand the changes that have occurred on the data model. (Comparison: Viewer mode (software design mode))
  • A model notifies its associated views and controllers when there have been a change in its state. This notification allows the produce updated output, and the controllers to change the available set of commands. In some cases a MVC implementation might instead be ' passive, ' so ' other components must poll ' the model for updates Rather than being notified.
  • View ( View ) to achieve a purposeful display of data (theoretically, this is not required). There is generally no logic on the program in the view. To implement the refresh feature on the view, the view needs to access the data model it monitors, so it should be registered with the data it is monitoring beforehand.
  • A View requests information from the model so it uses to generate an output representation to the user.
  • Controller ( Controller ) plays an organizational role across different levels to control the flow of applications . It handles the event and responds. An " event " includes the user's behavior and changes on the data model.
    • A controller can send commands to the model to update the model's state (e.g., editing a document). It can also send commands to their associated view to change the view's presentation of the model (e.g., by scrolling throug H a document).

Encyclopedia MVC Data Flow Diagram

MVC component type relationship and function diagram

Advantages:

1, Multiple views can share a model . Such as: Requires the Web site to provide both an Internet interface and a WAP interface. In MVC design mode, the model responds to user requests and returns response data, the view is responsible for formatting the data and presenting them to the user, business logic and presentation layer separation, the same model can be reused by different views, so greatly improve the reusability of the code.

2, the controller is self-contained (self-contained) refers to the high -independence of the object, and the model and the image is relatively independent, so you can easily change the application data layer and business rules.

3. The controller improves the flexibility and configuration of the application. Controllers can be used to connect different models and views to complete the user's needs, or to construct applications that provide a powerful tool. Given some reusable models and views, the controller can select the appropriate model to process according to the user's needs, and then select the appropriate view to display the processing results to the user.

An overview of the MVC architecture pattern

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.