Design Patterns in MVC

Source: Internet
Author: User

Mvc. The model is the Application object, the view is its identity on the screen, and the controller controllers define how the user interface responds to user input.

MVC separates views and models by creating a "subscription/notification" protocol. The view must ensure that its display correctly responds to the state of the model. Once the model's data changes, the model informs about the view, and each view correspondingly gets the opportunity to refresh itself. This approach allows you to provide a different view representation for a model, as well as create a new view of a model without having to rewrite the model.

It reflects the design of separating views and models, but this design can also be used to solve the problem of separating objects so that changes in one object can affect other objects, and this object does not need to know the details of those objects that are affected. This more general design is described as OBSERVER (Observer mode).

Another feature of MVC is that views can be nested. MVC uses the subclass of the view class------The Compositeview class to support nested views. The object of the Compositeview class behaves like a view class object, and a combined view can be used wherever any view is available, but it contains and manages nested views.

Divides some objects into a group and uses that group of objects as an object. This design is described as composite (combined mode), which allows you to create a class hierarchy, where some subclasses define atomic objects (such as Button) and other classes define composite objects (Compositeview), which are more complex objects that are composed of atomic objects.

MVC allows you to change the way a view responds to input without changing the appearance of the view. MVC encapsulates the response mechanism in the Controller object. There is a controller's class hierarchy, which makes it easy to make appropriate changes to the original controller and create a new controller.

View uses an instance of the Controller subclass to implement a response policy for a feature. To implement a different response strategy, simply replace it with a different kind of controller instance. You can even notify the controller changing the view at run time to change how the view responds to user input. For example, a view can be banned from receiving any input, just give it a controller that ignores input events.

The View---Controller relationship is strategy (policy mode). A policy is an object that describes an algorithm. Policy patterns are useful when you want to replace an algorithm statically or dynamically, or if you have many different algorithms, or if the algorithm contains complex data structures that you want to encapsulate.

Design Patterns in 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.