On the MVC pattern

Source: Internet
Author: User

MVC mode (three-tier architecture mode)

(Model-view-controller) is a software architecture model in software engineering that divides software systems into three basic parts: model, view, and controller.

The MVC pattern was first proposed by Trygve Reenskaug in 1974 and is a software design pattern invented by Xerox PARC in the 1980s for the programming language Smalltalk (Palo Alto). The purpose of the MVC pattern is to implement a dynamic program design that simplifies the subsequent modification and expansion of the program, and makes it possible to reuse a part of the program. In addition, this mode makes the program structure more intuitive by simplifying the complexity. By separating the basic parts of the software system, it also gives the functions of each basic part. Professionals can be grouped by their own expertise:

    • (Controller controllers)-responsible for forwarding requests and processing requests.
    • (views view)-graphical interface design for interface designers.
    • (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).

How MVC works

MVC is a design pattern that makes it mandatory to separate the input, processing, and output of an application. Using an MVC application is divided into three core parts: model, view, controller. Each of them handles their own tasks.

View

A view is an interface that the user sees and interacts with. For older Web applications, views are an interface of HTML elements, and in modern Web applications, HTML still plays an important role in the view, but new technologies are emerging, including Macromedia Flash and like xhtml,xml/xsl   , WML, and some other identity languages and Web services. How to handle an application's interface becomes increasingly challenging. One big benefit of MVC is that it can handle many different views of your application. There is really no real processing happening in the view, whether the data is stored online or an employee list, as a view, it is simply a way to output data and allow the user to manipulate it.

Model

Models represent enterprise data and business rules. Of the three parts of MVC, the model has the most processing tasks. For example, it may use artifact objects such as EJBS and ColdFusion to process the database. The data returned by the model is neutral, meaning that the model is independent of the data format, so that a model can provide data for multiple views. Because the code applied to the model can be reused by multiple views only once, it reduces the repetition of the code.

Controller

The controller accepts the user's input and invokes the model and view to complete the user's needs. So when you click a hyperlink in a Web page and send an HTML form, the controller itself does not output anything and do any processing.   It simply receives the request and decides which model component is called to process the request, and then determines which view to use to display the data returned by the model processing. Now we summarize the process of MVC, first the controller receives the user's request and decides which model should be called to process it, then the model uses the business logic to process the user's request and return the data, and finally the controller formats the data returned by the model with the corresponding view and renders it to the user through the presentation layer.

Advantages of the MVC framework Pattern

1, the developer can only focus on the entire structure of one of the layers;
2, can easily use the new implementation to replace the original level of implementation;
3. Can reduce the dependence between layer and layer;
4, in favor of standardization;
5, facilitate the reuse of the logic of each layer.

Disadvantages of the MVC framework Pattern

(1) Increase the complexity of the system structure and implementation. For a simple interface, strict adherence to MVC, which separates the model, view, and controller, increases the complexity of the structure and may result in excessive update operations and reduced operational efficiency.

(2) The connection between the view and the controller is too tight. Views and controllers are separated from each other, but they do have a tight connection, the view has no controller, its application is very limited, and vice versa, which prevents them from being reused independently.

(3) A view of inefficient access to model data. Depending on the model operator interface, the view may need to be called multiple times to obtain sufficient display data. Unnecessary frequent access to unchanged data will also compromise operational performance.

On the MVC 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.