Chinaunix首页 | 论坛 | 博客
  • 博客访问: 257859
  • 博文数量: 60
  • 博客积分: 1222
  • 博客等级: 少尉
  • 技术积分: 585
  • 用 户 组: 普通用户
  • 注册时间: 2011-04-16 17:28
个人简介

从学通信的博士到从事IT行业的工程师 从原华为项目经理,到现任职公司架构师

文章分类

全部博文(60)

文章存档

2013年(18)

2012年(42)

我的朋友

分类: C/C++

2012-12-23 20:29:27

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 the visitor. 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.
阅读(807) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~