Chain of Reqonsibility
来源:互联网 发布:xd软件下载 编辑:程序博客网 时间:2024/05/16 11:23
动机:将发送者和处理者解耦。(提交请求的对象并不明确知道谁是最终的提供帮助的对象);
基本想法是给每个能处理请求的对象一个机会;
1)有多个对象可以处理一个请求,具体哪个对象处理由运行时决定;
2)不明确指定接收者
3)有可能该请求不会被处理;
1.Handler:
public abstract class Handler
{
protected Handler _successor;
public abstract void HandleRequest(int condition);
public void SetSuccessor(Handler successor)
{
_successor = successor;
}
}
2.ConcreteHandler
public class ConcreteHandler1 : Handler
{
public override void HandleRequest( int condition)
{
if (condition >= 1 && condition <= 10)
{
Console.WriteLine("{0} is processing this request", this.GetType().ToString());
}
else
{
_successor.HandleRequest(condition);
}
}
}
public class ConcreteHandler2 : Handler
{
public override void HandleRequest(int condition)
{
Console.WriteLine("{0} is processing this request", this.GetType().ToString());
}
}
3.Client
public class ClientHandler
{
public static void Handle()
{
int[] i = {1,2,3,4,5,10,11};
var handler1 = new ConcreteHandler1();
var handler2 = new ConcreteHandler2();
handler1.SetSuccessor(handler2);
foreach (var j in i)
{
handler1.HandleRequest(j);
}
}
}
- Chain of Reqonsibility
- 通讯兵(Chain of Responsibility)
- Chain of Responsibility
- Chain of Responsibility Pattern
- Chain of responsibility模式
- Chain of Responsibility pattern
- Chain of Responsibility模式
- Chain of Responsibility Pattern
- chain of Responsibility pattern
- Chain of Responsibility
- Chain of Responsibility
- Chain Of Responsibility模式
- Chain of Resposibility
- Chain Of Responsibility
- Chain Of Responsibility模式
- Chain of Responsibility 模式
- Chain of Responsibility Pattern
- Chain of Responsibility模式
- 2011-07-07 java读取ini配置文件
- Generic Makefile for C/C++ Program 通用Makefile
- 2011-07-06 defult 关键字 泛型 函数指针 及部分抄录
- 火狐中上传图片和IE上传图片类型的区别 写法
- javascript cookies 存、取、删除实例
- Chain of Reqonsibility
- Android OpenGL教程-第一课
- C++基础之字符数组和字符串
- Android2.1消息应用(Messaging)源码学习笔记
- iphone4 UI全用代码实现在
- 续:队列的应用 之 M/D/1队列
- Fatal error: Call to private MyObject::__construct() from invalid context
- Tomcat中支持shtml
- ie6,ie7,ie8和firefox下兼容的图片上传预览