责任链模式属于行为型设计模式之中的一个,怎么理解责任链?责任链是能够理解成数个对象首尾连接而成,每个节点就是一个对象。每个对象相应不同的处理逻辑,直至有一个对象响应处理请求结束。这一种模式成为责任链模式。

生活中能够找到责任链模式的原型吗?这样的样例非常多。比方你要去买房子。首先是销售人员(对象1)接待你。你说想要百分之3的折扣,没问题。这时销售人员就有打百分之三折扣的权限,销售人员(对象1)进行处理。这时来了一个土豪。说要买10套,要百分之五的折扣。销售人员(对象1)没有百分之五折扣的权限。必需要想上级领导,销售总监申请,销售总监(对象2)批复了申请。这时国民老公小王来了,小王说百分之十把楼盘全买了。这时销售总监(对象2)也没那么大的权限了。要向CEO申请批复。

也就是说每个客户(Client)都由销售人员接待,客户提出不同的权限,由销售人员交给不同的对象进行递次处理。客户并不关心哪个对象处理了他的请求,这样就减少了请求发送者和接受者之间的耦合关系。

以下我们通过一个出差差旅费批准为例,实现以下责任链模式。首先定义一个抽象的领导类:

package com.test.demo;

public abstract class Leader {
protected Leader nextHandler;//上一级领导 public final void handlerRequest(int money){
if(money<=limit() ){//小于限制,能够批复
handler(money);
}else{
if(nextHandler!=null){
nextHandler.handlerRequest(money);//交给上一级领导处理
}
}
}
/*
* 批款限额
*/
public abstract int limit();
/*
* 批款
*/
public abstract void handler(int money); }

这是一个抽象类。以下通过几个类继承它,首先是小组长类:

package com.test.demo;

public class GroupLeader extends Leader {

	public int limit() {
return 1000;//说明小组长有1000元的批复权限
} public void handler(int money) {
System.out.println("小组长批复了"+money); } }

主管类:

package com.test.demo;

public class Director extends Leader {

	@Override
public int limit() {
return 5000;
} @Override
public void handler(int money) {
System.out.println("主管批复了"+money); } }

经理类:

package com.test.demo;

public class Manager extends Leader {

	@Override
public int limit() {
return 10000;
} @Override
public void handler(int money) {
System.out.println("经理批复了"+money); } }

老板类:

package com.test.demo;

public class CEO extends Leader {

	@Override
public int limit() {
return Integer.MAX_VALUE;
} @Override
public void handler(int money) {
System.out.println("CEO批复了"+money);
} }

老板类无上限。以下来定义一个职员小张申请差旅报销:

package com.test.demo;

public class XiaoZhang {

	public static void main(String[] args) {
GroupLeader groupLeader=new GroupLeader();
Director director=new Director();
Manager manager=new Manager();
CEO ceo=new CEO();
groupLeader.nextHandler=director;
director.nextHandler=manager;
manager.nextHandler=ceo; groupLeader.handlerRequest(50000);
groupLeader.handlerRequest(500);
groupLeader.handlerRequest(5000); } }

小张一共像小组长申请了三笔,这时执行实比例如以下:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAREAAABtCAYAAACGA1WAAAAcvElEQVR4Ae1da2wc13X+dvnUg5K4khxbflAid2mJtsxYoeNwlTSqK8Qg5QAUohJIU8hBCSx/ivzhf3ZRQAIKVD+4/Em2RCqhCBpFqDaNvYuksqMmEdUkjGRaMhVzV5ToyA/ZDmnqRYmPneLcmTt7Z3b2SVJLrs4QxN6Z+zjnfPfOmXPP3HvGpWmaBuP48JNpmRS/Tz22ynLOJ4wAI/DwIXDp8lV4NlSlFLw0ZU6KjPeHI6iq8sDtLkVcc2FecyEed4t0PO5CXHOb11zuUmx9cguq1q5O0RpfZgTyQ2Dsjz+GK0VVzQU8saMV5as2pCjBl3NBwO12w+VKhTaQsxKJx+dQsXkH1peXCz7iGiD/yaSZ14AvJmewrqoMszMzGB27jponHsMmT2pNlotAXJYRIARm7t3Ctl3fdwTj89gv8eHFEJ7c2YYKViSOGOVy0e1ywe1OViLv//kO/uVnH+auRARxlwslpeXQZudw791h3H//fbjWrEHlN7+Fss2PIB6/j9LSMpSXl2PzlhJc//QvrERy6TUumxEBTXOhpNz5wbS6ahMAF8bf+zlqnvsuK5KMaKYvQArEyRL5x59cw6ap38Odvnr63OkLFxB/911sLCvB2ju3cPcXv0iqULmqEnfv3k+6vnQXpjB8agBnxlNRGMeZgTNImZ2q2gO+/uXdGVz+aBL/O/IxLlz9Al8+UAzzEHb8DAZODWMqj6r5VCHrl7x59P+HDz7Gyd+M4M69WXHuLinF6ioPVq9ejbHhn+XT/CLVeUBjbWoYpwZOYX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EPv2FNQVooZtWglleerM+/jECRI5C7EskBEFIA5o2LgBZQpyG8zT8HJLkoI7B8EeBQAGyQMgKMwIIQyM8nsiCSXJkRYASKCQFWIsXUmywLI1AABFiJFAB0JskIFBMCrESKqTdZFkagAAiwEikA6EySESgmBFiJFFNvsiyMQAEQYCVSANCZJCNQTAiwEimm3mRZGIECIMBKpACgM0lGoJgQYCVSTL3JsjACBUCAlUgBQGeSjEAxIcBKpJh6k2VhBAqAACuRAoDOJBmBYkKAlUgx9SbLwggUAAFWIgUAnUkyAsWEACuRYupNloURKAACrEQKADqTZASKCQFWIsXUmywLI1AABFiJFAB0JskIFBMCrESKqTdZFkagAAiwEikA6EySESgmBFiJFFNvsiyMQAEQYCVSANCZJCNQTAj8Pzlxz+tOWVt1AAAAAElFTkSuQmCC" alt="" />

我们能够看到不同的款项由不同的对象进行了处理。小张并不关心谁处理的,他仅仅要找小组长就可以。这就是责任链模式的特点。

喜欢的朋友关注,谢谢

Java与设计模式-责任链模式的更多相关文章

  1. java 设计模式 -- 责任链模式

    设计模式 – 责任链模式 介绍: 责任链模式是一种动态行为模式,有多个对象,每一个对象分别拥有其下家的引用.连起来形成一条链.待处理对象则传到此链上,在此链进行传递,且待处理对象并不知道此会被链上的哪 ...

  2. 【设计模式】Java设计模式 - 责任链模式

    [设计模式]Java设计模式 - 责任链模式 不断学习才是王道 继续踏上学习之路,学之分享笔记 总有一天我也能像各位大佬一样 一个有梦有戏的人 @怒放吧德德 目录 [设计模式]Java设计模式 - 责 ...

  3. 浅谈Python设计模式 -- 责任链模式

    声明:本系列文章主要参考<精通Python设计模式>一书,并且参考一些资料,结合自己的一些看法来总结而来. 之前在最开始就聊了Python设计模式有三种,其中关于创建型和结构型设计模式基本 ...

  4. 我的Java设计模式-责任链模式

    今天来说说程序员小猿和产品就关于需求发生的故事.前不久,小猿收到了产品的需求. 产品经理:小猿,为了迎合大众屌丝用户的口味,我们要放一张图,要露点的. 小猿:......露点?你大爷的,让身为正义与纯 ...

  5. Java设计模式-责任链模式

    提出问题: 最初接触责任链模式就是在struts2中,在当时学的时候看了一眼,大概知道了原理,最近在复习,模拟struts2,说是模拟只是大体模拟了struts2的工作流程,很多东西都是写死的,只是为 ...

  6. Java设计模式の责任链模式

    在阎宏博士的<JAVA与模式>一书中开头是这样描述责任链(Chain of Responsibility)模式的: 责任链模式是一种对象的行为模式.在责任链模式里,很多对象由每一个对象对其 ...

  7. Java设计模式-责任链模式(Chain of Responsibility)

    接下来我们将要谈谈责任链模式,有多个对象,每个对象持有对下一个对象的引用,这样就会形成一条链,请求在这条链上传递,直到某一对象决定处理该请求.但是发出者并不清楚到底最终那个对象会处理该请求,所以,责任 ...

  8. Java设计模式—责任链模式

    责任链模式的定义: 使多个对象都有机会处理请求,从而避免了请求的发送者和接受者之间的耦合关系.将这些对象连成一条链,并沿着这条链传递该请求,直到有对象处理它为止. 责任链模式的重点是在"链& ...

  9. php 23种设计模式 - 责任链模式

    责任链模式 责任链模式(Chain of Responsibility Pattern)为请求创建了一个接收者对象的链.这种模式给予请求的类型,对请求的发送者和接收者进行解耦.这种类型的设计模式属于行 ...

随机推荐

  1. 简单实用jstl实现代码编写

    package com.ceshi; import java.io.IOException; import javax.servlet.jsp.JspException; import javax.s ...

  2. kb-01-d<poj3279>--深搜变种,二进制优化;

    poj--3279 题意: 给n*m的矩阵,0 1组成,每次翻转一个格子可以将上下左右的五个节点翻转,求,把所有的格子翻转成0:输出每个个字的翻转次数:最少字数: 做法: 从上到下,第一行翻转的情况确 ...

  3. HUST——1106xor的难题之二(异或树状数组单点修改和区间查询)

    1106: xor的难题之二 时间限制: 2 Sec  内存限制: 128 MB 提交: 8  解决: 3 题目描述 上次Alex学长的问题xor难题很简单吧,现在hkhv学长有个问题想问你们. 他现 ...

  4. K3Cloud调用存储过程

    SQLScriptServiceHelper.GetDataFromStoredProc( this.Context, DatabaseType.Oracle, "/*dialect*/TJ ...

  5. 【POJ2104】K-th Number(主席树)

    题意:有n个数组成的序列,要求维护数据结构支持在线的下列两种操作: 1:单点修改,将第x个数修改成y 2:区间查询,询问从第x个数到第y个之间第K大的数 n<=100000,a[i]<=1 ...

  6. 【BZOJ1103】大都市meg(DFS序,树状数组)

    题意:有一颗树,1号点为根,保证编号小的点深度较小,初始状态每条边都没有被标记,要求实现两个操作在线: A:将连接x,y的边标记 W:查询从1到x的路径上有多少条边未被标记 n<=2*10^5 ...

  7. linux之Deamon进程创建及其进程exit,_exit,return之间的区别

    Dameon进程又被称做守护进程,一般来说他有以下2个特点: 1.生命周期非常长,一旦启动,一般不会终止,直到系统推出,不过dameon进程可以通过stop或者发送信号将其杀死 2.在后台执行,不跟任 ...

  8. Linux 之 xunsearch

    Linux 之 xunsearch 参考教程:[千峰教育] 一.xunsearch简介: 开源免费.高性能.多功能.简单易用的专业全文检索技术方案. 官网(http://xunsearch.com). ...

  9. js-classList修改class属性

    classList定义与用法 1)classList属性返回元素的类名,作为DOMTokenList对象 2)该属性用于在元素中添加,移除及切换css类 3)classList属性是只读的,但可以用a ...

  10. Codeforces 946 B.Weird Subtraction Process

    B. Weird Subtraction Process   time limit per test 1 second memory limit per test 256 megabytes inpu ...