设计模式之13 - 责任链模式Chain Of Responsibility
来源:互联网 发布:索尼电视软件更新 编辑:程序博客网 时间:2024/06/08 06:43
条件判断 在编程中是应用最广的,他决定了程序的下一步应该怎么执行。我们来看下面一段代码:
// 条件判断string strType = "";if(age<3) strType = "未入学";else if(age<6) strType = "幼儿园";else if(age<12) strType = "小学";else if(age<15) strType = "初中";else if(age<18) strType = "高中";else if(age<22) strType = "大学";else if(age<25) strType = "研究生";else if(age<28) strType = "博士";else strType = "已毕业";再来看下 switch case 的情况:
// Switchvoid divide(int i){ switch(i) { case 1: case 2: case 3: case 4: case 5: …… }}
上述两种情况 都是属于 责任链的概念。
责任链模式 将多个对象定义成一个链式结构,按照顺序对请求进行判断和处理,直到有一个对象处理他为止。
这个结构非常容易理解,像代码中 经常会用到的 消息传递机制、windows窗口事件 等,都是属于责任链模式的应用。
责任链模式 的优点在于实现了 请求者 和 处理者 的代码分离,发出请求的调用者 不需要知道谁处理了这个消息,只需要将请求发送出去即可,大大提高了灵活性。
2 0
- 设计模式之13 - 责任链模式Chain Of Responsibility
- 设计模式之责任链Chain of Responsibility模式
- 设计模式之责任链模式(Chain of Responsibility)
- 设计模式之---责任链模式(Chain of Responsibility)
- 设计模式之责任链模式--- Pattern chain-of-responsibility
- 设计模式拾荒之责任链模式 ( Chain of Responsibility)
- 设计模式之责任链模式(Chain of Responsibility)
- 设计模式之二十一------ chain of responsibility(责任链)
- 设计模式之责任链(Chain of Responsibility)
- 设计模式之-责任链(Chain of responsibility )
- 设计模式之责任链Chain of Responsibility
- 【设计模式 - 13】之责任链模式(Chain Of Responsibility)
- 设计模式 - Chain of Responsibility Pattern(责任链模式)
- 设计模式 - Chain of Responsibility Pattern(责任链模式)
- 设计模式:责任链模式(Chain of Responsibility, CoR)
- 设计模式——责任链模式(Chain Of Responsibility)
- JAVA设计模式—责任链模式(Chain Of Responsibility)
- 设计模式初探-责任链模式(CHAIN OF RESPONSIBILITY)
- spring切面:注解:前后置增强(不带参数、函数详情)
- 在sublime中设置浏览器预览
- Android资源文件Res详解——ShapeDrawable
- Sublime Text2注册码
- spring切面:注解:前后置增强(带参数、函数详情)
- 设计模式之13 - 责任链模式Chain Of Responsibility
- dos命令解决进程无法关闭
- BNUOJ 27935 我爱背单词(FFT)
- Java虚拟机学习(2):垃圾收集算法
- spring切面:注解:环绕增强
- 设计模式之14 - 命令模式Command
- Java虚拟机学习(3): 类加载机制
- 寒假的c语言进阶
- rst