博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
design pattern notes [4] - chain of responsibility, visitor
阅读量:4676 次
发布时间:2019-06-09

本文共 1929 字,大约阅读时间需要 6 分钟。

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.

转载于:https://www.cnblogs.com/hanhuilee/archive/2012/12/13/5221429.html

你可能感兴趣的文章
C语言截取字符串
查看>>
如何查自己的账单
查看>>
JAVA8学习笔记(二)----三个预定义接口
查看>>
JDBC连接各种数据库的字符串
查看>>
构建之法阅读笔记06
查看>>
CentOS minimal新装配置笔记
查看>>
压缩映象原理的一个应用
查看>>
Aurora — 一个在 MSOffice 内输入 LaTeX 公式的很好用插件
查看>>
关于sql优化的一个小总结
查看>>
Java语言中的正则表达式
查看>>
Java环境变量设置
查看>>
【JBPM4】判断节点decision 方法3 handler
查看>>
filter 过滤器(监听)
查看>>
Linux进程间通信---共享内存
查看>>
Computer Information
查看>>
交换机/路由器上的 S口 F口 E口
查看>>
P1298(矩阵切割)DP
查看>>
wzplayer for delphi demo截图
查看>>
团队第二周:SRS文档
查看>>
Zookeeper的安装与使用:
查看>>