MVC Development Model

Source: Internet
Author: User

Introduction to the MVC pattern

MVC is an architectural pattern that does not introduce new functionality in itself, but simply directs us to improve the architecture of the application, separating the model and view of the application, and thus resulting in better development and maintenance efficiency.

In the MVC pattern, the application is divided into three parts of the model, view, and controller. The model part contains the business logic and business data of the application, the view part encapsulates the output form of the application, that is, the commonly referred page or interface, while the controller part coordinates the model and view, chooses which model to call to handle the business according to the user request. And ultimately which view is the answer for the user.

The three parts of the MVC pattern are very clear and separate, so each part can be independently changed without affecting the rest, thus greatly improving the flexibility and reusability of the application.

MVC Pattern Basics

In the MVC pattern, an application is divided into three parts of the model, view, and controller, followed by the three parts.

1 : First look at the role of the model, view, controller parts

    • Model: is responsible for encapsulating the status of the application and implementing the functionality of the application. Usually divided into data model and business logic model, the data model is used to store business data, such as order information, user information, and business logic model contains the business operations of the application, such as the addition or modification of orders.
    • View: Used to present the contents of the model to the user, who can request the model to be updated through a view. The view obtains the data to be displayed from the model, and then presents it to the user in its own way, which is equivalent to providing the interface to interact with the user, and when the user is working on the interface or completing the completion, it makes a request to the controller by clicking the Submit button or other triggering event.
    • Controller: Used to control the process of an application and to process requests made by the view. When the controller receives the user's request, the user's data is matched with the update of the model, that is, the function of invoking the model to implement the user's request, then the controller chooses the view for the response and presents the updated data to the user.

2 : Relationship of model and view

In MVC, the model and view are detached, usually there is no logical implementation in the view, and the model is not dependent on the view, the same model may have many different ways of presentation, that is, the same model can correspond to a variety of different views.

Such examples abound, for example, when browsing folders on a Windows operating system, the folders are those, the data does not change, but there are many ways to display them, such as large icons, small icons, detailed information, and many more. Take the file under the Tomcat7 folder as an example, in different ways, as shown in 1.1:

The difference between the MVC development pattern and the traditional development model

Model1 mode : The use of pure JSP or Jsp+javabean development, there are the following defects: JSP page mixed with HTML and Java code, so that the development of code and read the trouble, the late maintenance and expansion of the system is very difficult, For example, in the JSP page database connection and operation, if you need to make any changes to the database, you must open all the operation of the database JSP page to make the corresponding changes, when the page is very large, the workload is very big, the system is not easy to debug, due to HTML, JAVA, JavaScript is mixed together, you must start the server and invoke the JSP page to see the effect. Therefore, the model is suitable for small-scale web application development.
Jsp+javabean development, although the logical function and display function separation, but because the view layer and control layer are implemented by the JSP page, that is, the view layer and the control layer is not separated, so it still belongs to the MODEL1 mode.

Model2 mode --MVC Development mode
It is designed to overcome the shortcomings of Model1, the specific meaning of MVC is: Model+view+control, that is, model + view + control, such a mode integration of JSP, Serclet, JavaBean, very suitable for large-scale project development.

View layer :
The interface of representing and user interaction can be realized by HTML, XML, applet and so on, it is only responsible for data collection and processing (display). In JSP it is implemented separately by JSP pages.

model Layer :
It is often written using JavaBean, which accepts the data requested by the view layer, then carries out the corresponding business processing and returns the final processing result, it takes the responsibility of the most core, and uses the characteristics of JavaBean to realize the reuse and extension of code and to facilitate maintenance.

Control layer :
The control layer receives the request from the client and then passes the request to the model layer and tells the model layer what function module should be called to handle the request, which will coordinate the work between the view layer and the model layer, which is generally referred to Serclet.

The MVC development pattern is compared with the MODEL1 model, which shows the following features:
(1) Each layer accountability, non-interference. No disturbance to other layers after each update;
(2) The MVC development pattern is advantageous to the responsibility Division of labor, lets the specialized personnel each specialized layer's design, enhances the work efficiency and the quality;
(3) The components can be reused very well, because the division of labor is clear, the components of each layer can be separated into a reusable component.
However, the MVC development pattern is more complex than Model1, so it is more suitable for large and medium-sized project applications, while the MODEL1 model is suitable for small-scale web application development.

MVC Development Model

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.