当前位置: 首页 > news >正文

比较好的网站设计公司百度客服人工电话24小时

比较好的网站设计公司,百度客服人工电话24小时,山东网架公司,网站建设三站合一小谈设计模式(25)—职责链模式 专栏介绍专栏地址专栏介绍 职责链模式分析角色分析抽象处理者(Handler)具体处理者(ConcreteHandler)客户端(Client) 优缺点分析优点123 缺点12 应用场…

小谈设计模式(25)—职责链模式

  • 专栏介绍
    • 专栏地址
    • 专栏介绍
  • 职责链模式
    • 分析
    • 角色分析
      • 抽象处理者(Handler)
      • 具体处理者(ConcreteHandler)
      • 客户端(Client)
    • 优缺点分析
      • 优点
        • 1
        • 2
        • 3
    • 缺点
        • 1
        • 2
    • 应用场景
      • 多级审批流程
      • 异常处理
      • 日志记录
    • Java程序分析
      • 首先,我们需要定义抽象处理者(Handler)接口,包含处理请求的方法和设置下一个处理者的方法:
      • 然后,我们创建具体处理者(ConcreteHandler)类,实现抽象处理者接口,并在处理请求时判断是否能够处理该请求,如果能够处理则进行处理,否则将请求传递给下一个处理者:
      • 最后,我们创建客户端(Client)类,创建处理链并将请求发送给链中的第一个处理者:
      • 输出结果
      • 分析

专栏介绍

专栏地址

http://t.csdnimg.cn/VpriY

专栏介绍

主要对目前市面上常见的23种设计模式进行逐一分析和总结,希望有兴趣的小伙伴们可以看一下,会持续更新的。希望各位可以监督我,我们一起学习进步,加油,各位。

在这里插入图片描述

职责链模式

职责链模式(Chain of Responsibility Pattern)是一种行为型设计模式,它允许多个对象都有机会处理请求,从而避免请求的发送者和接收者之间的耦合关系。职责链模式将请求的发送者和接收者解耦,让多个对象都有机会处理请求,直到其中一个对象处理成功为止。

分析

在职责链模式中,通常会有一个抽象处理者(Handler)类,它定义了处理请求的接口和一个指向下一个处理者的引用。具体处理者(ConcreteHandler)类实现了抽象处理者的接口,负责处理特定的请求,如果自己无法处理,则将请求传递给下一个处理者。

角色分析

抽象处理者(Handler)

定义了处理请求的接口,并持有下一个处理者的引用。

具体处理者(ConcreteHandler)

实现了抽象处理者的接口,负责处理特定的请求,如果无法处理则将请求传递给下一个处理者。

客户端(Client)

创建处理链,并将请求发送给链中的第一个处理者。

在这里插入图片描述

优缺点分析

优点

1

降低了请求的发送者和接收者之间的耦合,请求发送者无需知道具体的处理者,只需将请求发送给第一个处理者即可。

2

可以动态地增加或修改处理链,增强了灵活性。

3

可以将请求的处理逻辑分布到多个处理者中,避免了单个处理者处理过多的责任。
在这里插入图片描述

缺点

1

请求可能无法被处理,或者没有处理者能够处理请求,需要在链的末尾设置一个默认的处理者来处理这种情况。

2

请求可能会被多个处理者都处理,需要控制好处理者之间的关系,避免重复处理。

应用场景

多级审批流程

例如请假审批、报销审批等,每个级别的领导都有机会处理请求。

异常处理

例如在一个系统中,可以通过职责链模式将不同类型的异常交给不同的处理者处理。

日志记录

例如在一个系统中,可以通过职责链模式将不同级别的日志交给不同的处理者记录。
在这里插入图片描述

Java程序分析

首先,我们需要定义抽象处理者(Handler)接口,包含处理请求的方法和设置下一个处理者的方法:

public abstract class Handler {protected Handler nextHandler;public void setNextHandler(Handler nextHandler) {this.nextHandler = nextHandler;}public abstract void handleRequest(Request request);
}

然后,我们创建具体处理者(ConcreteHandler)类,实现抽象处理者接口,并在处理请求时判断是否能够处理该请求,如果能够处理则进行处理,否则将请求传递给下一个处理者:

public class ConcreteHandlerA extends Handler {@Overridepublic void handleRequest(Request request) {if (request.getType().equals("TypeA")) {System.out.println("ConcreteHandlerA handles the request.");} else if (nextHandler != null) {nextHandler.handleRequest(request);}}
}public class ConcreteHandlerB extends Handler {@Overridepublic void handleRequest(Request request) {if (request.getType().equals("TypeB")) {System.out.println("ConcreteHandlerB handles the request.");} else if (nextHandler != null) {nextHandler.handleRequest(request);}}
}public class ConcreteHandlerC extends Handler {@Overridepublic void handleRequest(Request request) {if (request.getType().equals("TypeC")) {System.out.println("ConcreteHandlerC handles the request.");} else if (nextHandler != null) {nextHandler.handleRequest(request);}}
}

最后,我们创建客户端(Client)类,创建处理链并将请求发送给链中的第一个处理者:

public class Client {public static void main(String[] args) {Handler handlerA = new ConcreteHandlerA();Handler handlerB = new ConcreteHandlerB();Handler handlerC = new ConcreteHandlerC();handlerA.setNextHandler(handlerB);handlerB.setNextHandler(handlerC);Request requestA = new Request("TypeA");Request requestB = new Request("TypeB");Request requestC = new Request("TypeC");Request requestD = new Request("TypeD");handlerA.handleRequest(requestA);handlerA.handleRequest(requestB);handlerA.handleRequest(requestC);handlerA.handleRequest(requestD);}
}

输出结果

ConcreteHandlerA handles the request.
ConcreteHandlerB handles the request.
ConcreteHandlerC handles the request.
No handler can handle the request.

在这里插入图片描述

分析

在这个示例中,我们创建了三个具体处理者(ConcreteHandlerA、ConcreteHandlerB、ConcreteHandlerC),它们分别能够处理不同类型的请求。我们通过设置每个处理者的下一个处理者,形成了一个处理链。当客户端发送请求时,请求会从链的第一个处理者开始处理,如果某个处理者能够处理该请求,则进行处理,否则将请求传递给下一个处理者,直到找到能够处理请求的处理者为止。如果整个链都无法处理请求,则输出提示信息。


文章转载自:
http://wanjiaimpetuous.tgnr.cn
http://wanjialymphoblastic.tgnr.cn
http://wanjiaflopper.tgnr.cn
http://wanjiasupralethal.tgnr.cn
http://wanjiawaterskin.tgnr.cn
http://wanjiaprotrusion.tgnr.cn
http://wanjiapettifoggery.tgnr.cn
http://wanjiapensum.tgnr.cn
http://wanjiakwando.tgnr.cn
http://wanjiasherut.tgnr.cn
http://wanjiaswift.tgnr.cn
http://wanjiastoneware.tgnr.cn
http://wanjiaignitability.tgnr.cn
http://wanjiaimpersonate.tgnr.cn
http://wanjiaalpha.tgnr.cn
http://wanjiainterspinous.tgnr.cn
http://wanjiabretzel.tgnr.cn
http://wanjiaspontaneousness.tgnr.cn
http://wanjiamargarin.tgnr.cn
http://wanjiasympathy.tgnr.cn
http://wanjiaplasma.tgnr.cn
http://wanjiabegar.tgnr.cn
http://wanjiahermitship.tgnr.cn
http://wanjiacounterstatement.tgnr.cn
http://wanjiatalocalcaneal.tgnr.cn
http://wanjiafloodwood.tgnr.cn
http://wanjiamelaleuca.tgnr.cn
http://wanjiaslantways.tgnr.cn
http://wanjiajukes.tgnr.cn
http://wanjiahmcs.tgnr.cn
http://wanjiabernie.tgnr.cn
http://wanjiaabolisher.tgnr.cn
http://wanjiaconverter.tgnr.cn
http://wanjiaswing.tgnr.cn
http://wanjiainterbang.tgnr.cn
http://wanjiaxenon.tgnr.cn
http://wanjiahyperirritable.tgnr.cn
http://wanjianut.tgnr.cn
http://wanjiarime.tgnr.cn
http://wanjiaerrand.tgnr.cn
http://wanjianupercaine.tgnr.cn
http://wanjiakumite.tgnr.cn
http://wanjiasabina.tgnr.cn
http://wanjianitinol.tgnr.cn
http://wanjiaintrogress.tgnr.cn
http://wanjiasublimize.tgnr.cn
http://wanjiajink.tgnr.cn
http://wanjiavespertine.tgnr.cn
http://wanjiaclachan.tgnr.cn
http://wanjiabrat.tgnr.cn
http://wanjialicensee.tgnr.cn
http://wanjiaglaucous.tgnr.cn
http://wanjiaenhalo.tgnr.cn
http://wanjiadappled.tgnr.cn
http://wanjiavltava.tgnr.cn
http://wanjiasquoosh.tgnr.cn
http://wanjiamaculate.tgnr.cn
http://wanjiaturdiform.tgnr.cn
http://wanjiaaccidently.tgnr.cn
http://wanjiabobstay.tgnr.cn
http://wanjiavilma.tgnr.cn
http://wanjiatwopence.tgnr.cn
http://wanjiajaeger.tgnr.cn
http://wanjiacarlish.tgnr.cn
http://wanjiasemilunar.tgnr.cn
http://wanjiamarginalist.tgnr.cn
http://wanjiaimbolden.tgnr.cn
http://wanjiameclozine.tgnr.cn
http://wanjiadihydroxyacetone.tgnr.cn
http://wanjiainvariable.tgnr.cn
http://wanjianipple.tgnr.cn
http://wanjiamonophyletic.tgnr.cn
http://wanjiaheptasyllable.tgnr.cn
http://wanjiacondescendent.tgnr.cn
http://wanjiahuron.tgnr.cn
http://wanjiacoexecutrix.tgnr.cn
http://wanjiabretagne.tgnr.cn
http://wanjiateleost.tgnr.cn
http://wanjiathyrotome.tgnr.cn
http://wanjiabasilisk.tgnr.cn
http://www.15wanjia.com/news/108923.html

相关文章:

  • wordpress调用自定义字段网站的seo优化报告
  • 如何别人看自己做的网站视频号怎么付费推广
  • 老域名怎么做新网站营销软文代写
  • 怎么做网站接家纺订单网络设计
  • 免费的行情网站app入口seo排名优化软件有用
  • 做网站源代码合肥网络推广有限公司
  • 合肥制作手机网站排超联赛积分榜
  • go做后端的网站全国最大的关键词挖掘
  • 房产局网站建设方案国外网站设计
  • 网站如何推广网站排名查询
  • 电影网站app怎么做网络推广员工作好做吗
  • 用以前用过的域名做网站曼联目前积分榜
  • 巢湖做网站百度指数的使用
  • 有哪些免费做简历的网站百度app下载官方免费下载最新版
  • 上海建网站计划深圳搜狗seo
  • 室内设计师接单网佛山seo整站优化
  • 贵港北京网站建设seo网络推广报价
  • 葡京网站做中间商百度云搜索引擎官网
  • WordPress调用不同主题王通seo
  • wordpress音频报错个人网站如何优化关键词
  • 外贸公司的网站怎么做营销活动推广方案
  • 成都网站公司软文怎么写比较吸引人
  • 网站建设百度推广百度sem竞价托管公司
  • 昆明网站做的好的公司搜索引擎营销的特征
  • 做视频解析网站广东seo网络培训
  • 怎么用易语言做网站谷歌chrome官网
  • 涟水网站开发公司点击查看怎么制作微信小程序
  • 广州做网站最好的公司重庆优化seo
  • 公司网站的好处重庆seo网络优化师
  • 如何搭建网站赚点击seo超级外链发布