码迷,mamicode.com
首页 > 其他好文 > 详细

design_model(12)chain

时间:2018-09-01 15:18:41      阅读:126      评论:0      收藏:0      [点我收藏+]

标签: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);
	}
}

 

design_model(12)chain

标签:nbsp   his   inter   chain   apply   des   cli   sig   interface   

原文地址:https://www.cnblogs.com/gg128/p/9570292.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!