设计模式6--责任链模式(The chain of responsibility pattern)
来源:互联网 发布:软件开发网上兼职 编辑:程序博客网 时间:2024/05/22 06:22
如果一个处理不了,就传给链上的小一个来处理。
subject notification subject1
subject notification subject1
subject-->object1-->object2-->object3
interface HelpInterface{public void getHelp(int helpConstant);}public class FrontEnd implements HelpInterface{final int FRONT_END_HELP = 1;HelpInterface successor;public FrontEnd(HelpInterface s){successor = s;}public void getHelp(int helpConstant){if(helpConstant != FRONT_END_HELP) {successor.getHelp(helpConstant);} else {System.out.println("This is the front end.");}} }public class IntermediateLayer implements HelpInterface{final int INTERMEDIATE_LAYER_HELP = 2;HelpInterface successor;public FrontEnd(HelpInterface s){successor = s;}public void getHelp(int helpConstant){if(helpConstant != INTERMEDIATE_LAYER_HELP) {successor.getHelp(helpConstant);} else {System.out.println("This is the IntermediateLayer.");}} }public class Application implements HelpInterface{public Application(){}public void getHelp(int helpConstant){System.out.println("This is the MegaGigaCo application.");} }public class TestHelp{public static void main(String args[]){final int FRONT_END_HELP = 1;final int INTERMEDIATE_LAYER_HELP = 2;final int GENERAL_HELP = 3;Application app = new Application();IntermediateLayer intermediateLayer = new IntermediateLayer(app);FrontEnd frontEnd = new FrontEnd(intermediateLayer);frontEnd.getHelp(GENERAL_HELP);}}
0 0
- 设计模式6--责任链模式(The chain of responsibility pattern)
- 【设计模式】责任链模式(Chain of Responsibility Pattern)
- 设计模式 - Chain of Responsibility Pattern(责任链模式)
- 设计模式 - Chain of Responsibility Pattern(责任链模式)
- 设计模式之责任链模式--- Pattern chain-of-responsibility
- Java设计模式--责任链模式【Chain of Responsibility Pattern】
- 设计模式【责任链模式Chain of Responsibility Pattern】
- 责任链模式(Chain of Responsibility Pattern)
- 责任链模式(Chain of Responsibility Pattern)
- 责任链模式【CHAIN OF RESPONSIBILITY PATTERN 】
- 责任链模式【Chain of Responsibility Pattern】
- 责任链模式(Chain of Responsibility Pattern)
- 责任链模式(Chain of Responsibility Pattern)
- 责任链模式【Chain of Responsibility Pattern】
- 责任链模式 Chain of Responsibility Pattern
- 责任链模式【Chain of Responsibility Pattern】
- 责任链模式【Chain of Responsibility Pattern】
- 责任链模式--Chain of Responsibility Pattern
- 解决maven编译spark1.5报错问题
- OpenSessionInView详解
- leetcode笔记:Plus One
- APP运营推广超级攻略(2015新版)
- jvm
- 设计模式6--责任链模式(The chain of responsibility pattern)
- Who-are-the-top-Java-experts-in-the-world
- 模拟网易新闻主页的滚动效果
- 背景全屏样式
- 获取域名和ip
- 【排序】冒泡排序法
- 记一次基于Unity的Profiler性能分析
- Hibernate.initialize(Obj)用法
- 剑指Offer系列---(19)合并两个排序的链表