design_model(12)chain

Posted gg128

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了design_model(12)chain相关的知识,希望对你有一定的参考价值。

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);
	}
}

 

以上是关于design_model(12)chain的主要内容,如果未能解决你的问题,请参考以下文章

design_model(11)flyweight

design_model(16)template

design_model(18)observe

design_model(24)分类与备注

Chain 2 Renderscript Intrinsics:模糊和色彩矩阵

VSCode自定义代码片段12——JavaScript的Promise对象