否则,交给部门经理,部门经理审核后,无论是否同意,审批直接结束
状态类
package com.cmc; public abstract class State { public abstract void shenPi(Work w); }
package com.cmc; public class ProjectManager extends State { @Override public void shenPi(Work w) { if(w.isManagermentAccept()==false){ System.out.println("项目经理不同意,审批结束!"); }else{ if(w.getDay()<=3){ System.out.println("请假时间在三天以内,项目经理同意,审批结束"); }else{ System.out.println("请假时间大于三天,移交给部门经理处理!"); w.setCurrent(new PartmentMeneger()); w.shenPi(); } } } }部门经理类:
package com.cmc; public class PartmentMeneger extends State { @Override public void shenPi(Work w) { System.out.println("已经过部门经理审批,审批结束!"); } }
package com.cmc; public class Work { private State current; private int day; private boolean isManagermentAccept; public Work() { current = new ProjectManager(); } public State getCurrent() { return current; } public void setCurrent(State current) { this.current = current; } public int getDay() { return day; } public void setDay(int day) { this.day = day; } public boolean isManagermentAccept() { return isManagermentAccept; } public void setManagermentAccept(boolean isManagermentAccept) { this.isManagermentAccept = isManagermentAccept; } public void shenPi(){ current.shenPi(this); } }
客户端测试一下:
package com.cmc; public class Client { public static void main(String [] args){ Work w = new Work(); w.setDay(4); w.setManagermentAccept(true); w.shenPi(); } }
原文:http://blog.csdn.net/u014293306/article/details/46315781