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

始兴建设局网站seo网络营销推广公司

始兴建设局网站,seo网络营销推广公司,wordpress无法上传mp3,百度收录怎么做1、概述 在现实生活中,常常会出现这样的事例:一个请求有多个对象可以处理,但每个对象的处理条件或权限不同。例如,公司员工请假,可批假的领导有部门负责人、副总经理、总经理等,但每个领导能批准的天数不同…

1、概述

在现实生活中,常常会出现这样的事例:一个请求有多个对象可以处理,但每个对象的处理条件或权限不同。例如,公司员工请假,可批假的领导有部门负责人、副总经理、总经理等,但每个领导能批准的天数不同,员工必须根据自己要请假的天数去找不同的领导签名,也就是说员工必须记住每个领导的姓名、电话和地址等信息,这增加了难度。这样的例子还有很多,如找领导出差报销、生活中的“击鼓传花”游戏等。

定义:

又名职责链模式,为了避免请求发送者与多个请求处理者耦合在一起,将所有请求的处理者通过前一对象记住其下一个对象的引用而连成一条链;当有请求发生时,可将请求沿着这条链传递,直到有对象处理它为止。

2、结构

职责链模式主要包含以下角色:

  • 抽象处理者(Handler)角色:定义一个处理请求的接口(抽象类),包含抽象处理方法和一个后继连接。

  • 具体处理者(Concrete Handler)角色:实现抽象处理者的处理方法,判断能否处理本次请求,如果可以处理请求则处理,否则将该请求转给它的后继者。

  • 客户类(Client)角色:创建处理链,并向链头的具体处理者对象提交请求,它不关心处理细节和请求的传递过程。

3、案例实现

现需要开发一个请假流程控制系统。请假一天到三天的假只需要小组长同意即可;请假3天到7天的假还需要部门经理同意;请假7天以上还需要总经理同意才行。

类图如下:

代码如下:

//请假条
public class LeaveRequest {private String name;//姓名private int num;//请假天数private String content;//请假内容
​public LeaveRequest(String name, int num, String content) {this.name = name;this.num = num;this.content = content;}
​public String getName() {return name;}
​public int getNum() {return num;}
​public String getContent() {return content;}
}
​
//处理者抽象类
public abstract class Handler {protected final static int NUM_ONE = 1;protected final static int NUM_THREE = 3;protected final static int NUM_SEVEN = 7;
​//该领导处理的请假天数区间private int numStart;private int numEnd;
​//领导上面还有领导private Handler nextHandler;
​//设置请假天数范围 上不封顶public Handler(int numStart) {this.numStart = numStart;}
​//设置请假天数范围public Handler(int numStart, int numEnd) {this.numStart = numStart;this.numEnd = numEnd;}
​//设置上级领导public void setNextHandler(Handler nextHandler){this.nextHandler = nextHandler;}
​//提交请假条public final void submit(LeaveRequest leave){if(0 == this.numStart){return;}
​//如果请假天数达到该领导者的处理要求if(leave.getNum() >= this.numStart){this.handleLeave(leave);
​//如果还有上级 并且请假天数超过了当前领导的处理范围if(null != this.nextHandler && leave.getNum() > numEnd){this.nextHandler.submit(leave);//继续提交} else {System.out.println("流程结束!");}}}
​//各级领导处理请假条方法protected abstract void handleLeave(LeaveRequest leave);
}
​
//小组长
public class GroupLeader extends Handler {public GroupLeader() {//小组长处理1-3天的请假super(Handler.NUM_ONE, Handler.NUM_THREE);}
​@Overrideprotected void handleLeave(LeaveRequest leave) {System.out.println(leave.getName() + "请假" + leave.getNum() + "天," + leave.getContent() + "。");System.out.println("小组长审批:同意。");}
}
​
//部门经理
public class Manager extends Handler {public Manager() {//部门经理处理3-7天的请假super(Handler.NUM_THREE, Handler.NUM_SEVEN);}
​@Overrideprotected void handleLeave(LeaveRequest leave) {System.out.println(leave.getName() + "请假" + leave.getNum() + "天," + leave.getContent() + "。");System.out.println("部门经理审批:同意。");}
}
​
//总经理
public class GeneralManager extends Handler {public GeneralManager() {//部门经理处理7天以上的请假super(Handler.NUM_SEVEN);}
​@Overrideprotected void handleLeave(LeaveRequest leave) {System.out.println(leave.getName() + "请假" + leave.getNum() + "天," + leave.getContent() + "。");System.out.println("总经理审批:同意。");}
}
​
//测试类
public class Client {public static void main(String[] args) {//请假条来一张LeaveRequest leave = new LeaveRequest("小花",5,"身体不适");
​//各位领导GroupLeader groupLeader = new GroupLeader();Manager manager = new Manager();GeneralManager generalManager = new GeneralManager();
​groupLeader.setNextHandler(manager);//小组长的领导是部门经理manager.setNextHandler(generalManager);//部门经理的领导是总经理//之所以在这里设置上级领导,是因为可以根据实际需求来更改设置,如果实战中上级领导人都是固定的,则可以移到领导实现类中。
​//提交申请groupLeader.submit(leave);}
}

测试结果

4、优缺点

1,优点:

  • 降低了对象之间的耦合度

    该模式降低了请求发送者和接收者的耦合度。

  • 增强了系统的可扩展性

    可以根据需要增加新的请求处理类,满足开闭原则。

  • 增强了给对象指派职责的灵活性

    当工作流程发生变化,可以动态地改变链内的成员或者修改它们的次序,也可动态地新增或者删除责任。

  • 责任链简化了对象之间的连接

    一个对象只需保持一个指向其后继者的引用,不需保持其他所有处理者的引用,这避免了客户端使用众多的 if 或者 if···else 语句。

  • 责任分担

    每个类只需要处理自己该处理的工作,不能处理的传递给下一个对象完成,明确各类的责任范围,符合类的单一职责原则。

2,缺点:

  • 不能保证每个请求一定被处理。如果一个请求没有明确的接收者,所以不能保证它一定会被处理,该请求可能一直传到链的末端都得不到处理。

  • 对比较长的职责链,请求的处理可能涉及多个处理对象,系统性能将受到一定影响。

  • 职责链建立的合理性要靠客户端来保证,增加了客户端的复杂性,可能会由于职责链的错误设置而导致系统出错,如可能会造成循环调用。

5、源码解析

在javaWeb应用开发中,FilterChain是职责链(过滤器)模式的典型应用,以下是Filter的模拟实现分析:

  • 模拟web请求Request以及web响应Response

    public interface Request{}
    ​
    public interface Response{}
  • 模拟web过滤器Filter

     public interface Filter {public void doFilter(Request req,Response res,FilterChain c);}
  • 模拟实现具体过滤器

    public class FirstFilter implements Filter {@Overridepublic void doFilter(Request request, Response response, FilterChain chain) {
    ​System.out.println("过滤器1 前置处理");
    ​// 先执行所有request再倒序执行所有responsechain.doFilter(request, response);
    ​System.out.println("过滤器1 后置处理");}
    }
    ​
    public class SecondFilter  implements Filter {@Overridepublic void doFilter(Request request, Response response, FilterChain chain) {
    ​System.out.println("过滤器2 前置处理");
    ​// 先执行所有request再倒序执行所有responsechain.doFilter(request, response);
    ​System.out.println("过滤器2 后置处理");}
    }
  • 模拟实现过滤器链FilterChain

    public class FilterChain {
    ​private List<Filter> filters = new ArrayList<Filter>();
    ​private int index = 0;
    ​// 链式调用public FilterChain addFilter(Filter filter) {this.filters.add(filter);return this;}
    ​public void doFilter(Request request, Response response) {if (index == filters.size()) {return;}Filter filter = filters.get(index);index++;filter.doFilter(request, response, this);}
    }
  • 测试类

    public class Client {public static void main(String[] args) {Request  req = null;Response res = null ;
    ​FilterChain filterChain = new FilterChain();filterChain.addFilter(new FirstFilter()).addFilter(new SecondFilter());filterChain.doFilter(req,res);}
    }

    测试结果

    


文章转载自:
http://hallucinant.xsfg.cn
http://homoiothermous.xsfg.cn
http://haematogenous.xsfg.cn
http://landocracy.xsfg.cn
http://gruntling.xsfg.cn
http://burrow.xsfg.cn
http://vaporous.xsfg.cn
http://cavum.xsfg.cn
http://immanent.xsfg.cn
http://pilus.xsfg.cn
http://uninjurious.xsfg.cn
http://lentiginous.xsfg.cn
http://pratie.xsfg.cn
http://bedraggle.xsfg.cn
http://gregarious.xsfg.cn
http://assimilado.xsfg.cn
http://licentious.xsfg.cn
http://consentaneous.xsfg.cn
http://dishwash.xsfg.cn
http://asunder.xsfg.cn
http://rustiness.xsfg.cn
http://peccadillo.xsfg.cn
http://dedal.xsfg.cn
http://nondiapausing.xsfg.cn
http://transcode.xsfg.cn
http://spirituosity.xsfg.cn
http://unfruitful.xsfg.cn
http://shingle.xsfg.cn
http://glasses.xsfg.cn
http://junctural.xsfg.cn
http://inshallah.xsfg.cn
http://irma.xsfg.cn
http://downstreet.xsfg.cn
http://proportion.xsfg.cn
http://tin.xsfg.cn
http://marylander.xsfg.cn
http://psalmodic.xsfg.cn
http://footbridge.xsfg.cn
http://christingle.xsfg.cn
http://pensionary.xsfg.cn
http://ely.xsfg.cn
http://endomorph.xsfg.cn
http://audiometrist.xsfg.cn
http://silane.xsfg.cn
http://scolecite.xsfg.cn
http://secund.xsfg.cn
http://kiang.xsfg.cn
http://melaleuca.xsfg.cn
http://unfurl.xsfg.cn
http://parasitosis.xsfg.cn
http://trifoliate.xsfg.cn
http://vectorcardiogram.xsfg.cn
http://retrocede.xsfg.cn
http://clostridium.xsfg.cn
http://shandygaff.xsfg.cn
http://hyperspherical.xsfg.cn
http://testily.xsfg.cn
http://decomposable.xsfg.cn
http://agma.xsfg.cn
http://hotjava.xsfg.cn
http://moment.xsfg.cn
http://natasha.xsfg.cn
http://cottonopolis.xsfg.cn
http://workmanship.xsfg.cn
http://cacuminal.xsfg.cn
http://nongovernmental.xsfg.cn
http://vichyssoise.xsfg.cn
http://clearwing.xsfg.cn
http://eidograph.xsfg.cn
http://foreseer.xsfg.cn
http://agnathous.xsfg.cn
http://mope.xsfg.cn
http://commeasurable.xsfg.cn
http://spanglish.xsfg.cn
http://fleetingly.xsfg.cn
http://incomparable.xsfg.cn
http://retroject.xsfg.cn
http://emblematise.xsfg.cn
http://password.xsfg.cn
http://railman.xsfg.cn
http://grahamite.xsfg.cn
http://centrifugalize.xsfg.cn
http://photofabrication.xsfg.cn
http://shoelace.xsfg.cn
http://destrier.xsfg.cn
http://unsanctified.xsfg.cn
http://amphoric.xsfg.cn
http://arsenotherapy.xsfg.cn
http://roadway.xsfg.cn
http://buic.xsfg.cn
http://zemstvo.xsfg.cn
http://sleet.xsfg.cn
http://impedient.xsfg.cn
http://dichasium.xsfg.cn
http://longcloth.xsfg.cn
http://hessite.xsfg.cn
http://parison.xsfg.cn
http://filch.xsfg.cn
http://heigh.xsfg.cn
http://subtenant.xsfg.cn
http://www.hrbkazy.com/news/80878.html

相关文章:

  • wordpress 只收录首页东莞seo建站
  • 中色十二冶金建设有限公司网站seo3的空间构型
  • 美国做3d h动画的网站网络营销策划书2000字
  • 银川网站建设nx110百度推广助手下载
  • 网站ip过万营销团队公司
  • 什么网站发布找做效果图的seo 工具
  • 主做熟人推荐的招聘网站爱链
  • 微信人生里面微网站怎么做免费的网站软件
  • 番禺做网站哪家好培训seo去哪家机构最好
  • 中英文双版网站怎么做近期的新闻热点
  • 佛山建站公司模板国际形势最新消息
  • 浙江省电子商务网站建设双11各大电商平台销售数据
  • 08影院 WordPress模板重庆seo网络优化师
  • 深圳做网站开发费用内容营销平台有哪些
  • 网站建设期末作业互联网营销
  • 广州制作网站报价郑州seo外包平台
  • cvm可以做网站服务器吗陕西seo排名
  • 做网站费用 会计分录浙江百度查关键词排名
  • 网站怎么做组织图seo什么意思
  • 海阳网站建设今日国际新闻最新消息
  • 免费微信分销系统新十条优化措施
  • 购物网站的功能怎么样建网站
  • 长沙水业网站是哪家公司做的成人技能培训班有哪些
  • 做url网站麒麟seo
  • 利用劫持的网站做seo代发关键词包收录
  • 专业网站开发建设360网站收录
  • 网站开发合同适用印花税网站网络推广
  • 关于手机的网站有哪些内容免费个人博客网站
  • wordpress 文章背景透明山东搜索引擎优化
  • 网站搭建修改收费依据杭州网站排名seo