MVC is a composite design pattern for presentation layer design

Source: Internet
Author: User

MVC is a composite design pattern used to represent layer designs. M, V, and C represent the model, view, controller, respectively. Their duties are as follows:

They interact in the following ways:
 1. When the user makes any action on the view that needs to invoke the model, its request is intercepted by the controller.
 2. The controller translates the user behavior into model operation according to its own specified policy, and invokes the corresponding logical implementation of the model.
 3. The controller may specify a view to make certain changes when it receives a view operation.
 4. When the state of the model changes, the view is notified in some way.
 5. The view can get state from the model, thus changing its own display.
I'm going to introduce a design pattern calledobserve the (Observer) pattern.

, and the view can be arbitrarily replaced if the model is not changed. (As long as the IObserver is implemented)

2. Another place to use the interface in MVC is the controller, where I first introduce a design pattern: policy mode ( strategy). In MVC, this pattern is used by the controller.
As I said just now, the view is responsible for interacting with the user, however, it is only responsible for the interface display part, as for when the user did an action (such as click a button) after the system should react, the view is not responsible, it just put this action to the Controller, the controller according to the built-in strategy, the user operation translated into This means that the same view, the same operation, the model can react differently, depending on the controller's built-in strategy. So, we can have a lot of controllers in our system, they have different strategies, and when the view wants to change the policy, it can replace the controller. How to achieve it? This requires that the view cannot be coupled to a specific controller, but relies on only one controller interface (such as IController) and aggregates an instance of IController. When you want to change the policy, you can dynamically replace the controller while the system is running, which is the implementation of the policy mode.

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.