MVC(Model/View/Controller) consists of three kinds of objects. The Model is the application object, the view is its screen presentation, and the controller defines the way the user interface reacts to user input. MVC decouples views and models by establishing a subscribe/notify protocol between them. The model communicates with its views when its value change, and the views communicate with the model to access these values.And the design is applicable to a more general problem: decoupling objects so that changes to one can affect any number of others without requiring the changed object to know detail of the others.This more general design is described by the Observer Design Pattern.
Another feature of MVC is that views can be nested. MVC supports nested views with Composite View class, a subclass of View. We could think of this as a design that lets us treat a composite view just like we treat one of its components. But the design is applicable to a more general problem, which occurs whenever we want to group objects and treat the group like an individual object. This more general design is described by the Composite design pattern.
MVC encapsulates the response mechanism in a controller object. There is a class hierarchy
of controllers, making it easy to create a new controller as a variation on an existing one. A view uses an instance to implement a particular response strategy; to implement a different strategy, simply replace the instance with a different kind of controller. It's even possible to change a view's controller at run-time to let view change the way it responds to user input.
The view-controller relationship is an example of Strategy design pattern. A strategy is an object that represents and algorithm. It's useful when you want to replace the algorithm either statically or dynamically, when you have a lot of variants of the algorithm, or when the algorithm has complex data structures that you want to encapsulate.
MVC uses other design patterns, such as Factory Method to specify the default controller for a view and Decorator to add scrolling to a view. But the main relationship s in MVC are given by the Observer, Composite, and Strategy design patterns.
From::::::::::
<< design patterns: elements of reusable object-oriented software.>>
Sorry! I copied from the book section 1.2
阅读(805) | 评论(0) | 转发(0) |