标签:nbsp his inter chain apply des cli sig interface
1.责任链模式//设置不同的节点,完成不同的功能
2.实例
public interface Leader { public abstract void leave(Apply apl); } public class Manager implements Leader { private Leader leader; public void leave(Apply apply) { if(apply.getI()>5) { System.out.println("经理同意"); leader.leave(apply); }else { System.out.println("经理同意"); } } public Leader getLeader() { return leader; } public void setLeader(Leader leader) { this.leader = leader; } } public class Major implements Leader { public void leave(Apply apply) { System.out.println("总监同意"); } } public class Chain { public static void aplly(Apply apply) { Manager manager = new Manager(); Major major = new Major(); manager.setLeader(major); manager.leave(apply); } } public class Apply { private int i; public int getI() { return i; } public void setI(int i) { this.i = i; } } public class Client { public static void main(String[] args) { Apply apply = new Apply(); apply.setI(10); Chain chain = new Chain(); chain.aplly(apply); } }
标签:nbsp his inter chain apply des cli sig interface
原文地址:https://www.cnblogs.com/gg128/p/9570292.html