Introduction to MVC

Source: Internet
Author: User

In this semester in a hurry to learn the three main SSH framework, but also quite feeling. By comparison, SSH can be seen as a tool to fit the team's development with packaged classes to make our code easier to maintain. and MVC, compared to SSH, can be seen as a programming idea, an architectural model. He didn't want SSH to introduce a jar package and introduce functionality. But by knowing that we are improving our application architecture, the model and view of the application are separated, resulting in better development and maintenance efficiency.

Why is MVC there? It is said that in the early development, the structure of the program is not clear, the various parts of the function of confusion, in the business function changes, whether it is the business logic changes or display form modification, are to modify a lot of classes, "reaching", resulting in software development and maintenance inefficiencies, errors. and the MVC pattern to develop the system, will greatly avoid the occurrence of the above problems. The core approach of the MVC pattern is decoupling, and the MVC pattern divides the entire application into models, views, controllers three parts through careful partitioning, and then tightly controls the communication between the three parts, resulting in a clearly structured, functionally distributed, reusable, extensible, maintainable application

First, in the MVC pattern, we need to know what MVC is, where M is the model, V is the view, and C is the controller, and these three parts make up our MVC.

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, etc.

View: In layman's terms, it is the interface, including button images on the interface of the user to see the moral things, used to show the content of the model to the user, the user can request the model to update. For example, when the user in the interface operation or completion, will click the Submit button or other triggering events, to send a request to the controller.

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.

The component diagram of MVC describes the interactions between the three parts of the model, view, and controller, which are described in detail in the following order of interaction:

(1) The first is to display the view to the user, the user to operate on this view, and fill in some business data

(2) Then the user clicks the Submit button to make a request

(3) The user request from the view reaches the controller, which contains the business functions and related data to be completed in the request.

(4) The controller handles the user request, encapsulates the data in the request, selects and invokes the appropriate model, requests the model for status updates, and then selects the view to be presented to the user next.

(5) The model will handle the business functions requested by the user, while maintaining and updating the model State.

(6) When the model state changes, the model notifies the corresponding view, telling the view that its state has changed.

(7) When the view is notified by the model, it will make a status query to the model, get the data that needs to be presented, and then display the data according to how the view itself is displayed.

  

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.