design pattern notes [4] - chain of responsibility, visitor
2012-12-13 09:57
405 查看
chain of responsibility
When one object does not know which specific object will handle its request, the chain of responsibility can be used to forward request among all possible receivers to get final destination. The receivers are normally from same class hirarchy whose base
class is one action-handler composed of reference to next handler. The request can be forwarded from the most specific class to the most general class along inheritance structure.
Certainly the client may construct the chain by itself.
If an object structure contains many classes of objects with differing interaces.
Many distinct and unrelated operations need to be performed on objects in an object structure.
The classes defining the object structure rarely change, but you often want to define new operations over the structure.
The client creates one concrete visitor, and traverses the object structure, visiting each element with thevisitor. When an element is visited, it calls the Visitor operation that corresponds
to its class.
Visitor makes adding new operations easy.
Adding new concrete element class is hard. The abstrct class has to add new abstract operation.
Breaking encapsulation.
Notes more for clear understanding visitor:
Visitor let's you perform operations on elements of object structure without changing them. Two class hierarchies are defined: one for the elements of object structure being
performed operations and one for the visitors which will perform operations. We can subclass visitor to implement different operations.
The elements of object structure define Accept method and the visitors implement concrete Visit methods to visit concrete element by calling its public methods directly.
The object structure should rarely change especially for the interfaces which visitors will access otherwise the visitors have to be redefined frequently.
When one object does not know which specific object will handle its request, the chain of responsibility can be used to forward request among all possible receivers to get final destination. The receivers are normally from same class hirarchy whose base
class is one action-handler composed of reference to next handler. The request can be forwarded from the most specific class to the most general class along inheritance structure.
Certainly the client may construct the chain by itself.
If an object structure contains many classes of objects with differing interaces.
Many distinct and unrelated operations need to be performed on objects in an object structure.
The classes defining the object structure rarely change, but you often want to define new operations over the structure.
The client creates one concrete visitor, and traverses the object structure, visiting each element with thevisitor. When an element is visited, it calls the Visitor operation that corresponds
to its class.
Visitor makes adding new operations easy.
Adding new concrete element class is hard. The abstrct class has to add new abstract operation.
Breaking encapsulation.
Notes more for clear understanding visitor:
Visitor let's you perform operations on elements of object structure without changing them. Two class hierarchies are defined: one for the elements of object structure being
performed operations and one for the visitors which will perform operations. We can subclass visitor to implement different operations.
The elements of object structure define Accept method and the visitors implement concrete Visit methods to visit concrete element by calling its public methods directly.
The object structure should rarely change especially for the interfaces which visitors will access otherwise the visitors have to be redefined frequently.
相关文章推荐
- design pattern notes [4] - chain of responsibility, visitor
- Chain Of Responsibility Design Pattern Example
- Asp.net Design Pattern study notes -- PART 2
- Design Pattern Visitor 访问者模式
- design pattern——visitor
- 设计模式学习—责任链模式(Chain of Responsibility Design Pattern)
- Design Patterns Uncovered: The Visitor Pattern
- Design Patterns Uncovered: The Chain Of Responsibility Pattern
- design pattern notes [7] - state,strategy,memento,mediator,and iterator
- Design Pattern Visitor 访问者设计模式
- design pattern notes [7] - state,strategy,memento,mediator,and iterator
- Design Pattern – Visitor Pattern
- design pattern notes [1] - Bridge and composite
- design pattern notes [1] - Bridge and composite
- design pattern notes [5] - template method
- Visitor Design Pattern
- Core Design Patterns(16) Chain of Responsibility 职责链模式
- design pattern notes [2] - decorator, facade, Singleton, Flyweight, and Adapter
- design pattern notes [5] - template method
- design pattern notes [2] - decorator, facade, Singleton, Flyweight, and Adapter