加薪
经理-》总监-》总经理
package org.ustc.chain;
public abstract class Manager {
protected Manager supervisor;
protected String name;
public Manager( String name) {
this.name = name;
}
public Manager getSupervisor() {
return supervisor;
}
public void setSupervisor(Manager supervisor) {
this.supervisor = supervisor;
}
public abstract void handleRequest(Request req);
}
package org.ustc.chain;
public class ProjectManager extends Manager {
public ProjectManager(String name) {
super(name);
// TODO Auto-generated constructor stub
}
@Override
public void handleRequest(Request req) {
// TODO Auto-generated method stub
if(req.getNumber()<3&&req.getRequestType().equals("请假"))
System.out.println(this.name+"处理请假");
else
supervisor.handleRequest(req);
}
}
package org.ustc.chain;
public class ChiefManager extends Manager {
public ChiefManager(String name) {
super( name);
// TODO Auto-generated constructor stub
}
@Override
public void handleRequest(Request req) {
// TODO Auto-generated method stub
if(req.getRequestType().equals("请假")&&req.getNumber()<10)
System.out.println(this.name+"处理请假请求");
else if(req.getRequestType().equals("加薪")&&req.getNumber()<500)
System.out.println(this.name+"处理加薪请求");
else
System.out.println("等等再说吧");
}
}
package org.ustc.chain;
public class Director extends Manager{
public Director( String name) {
super( name);
// TODO Auto-generated constructor stub
}
@Override
public void handleRequest(Request req) {
// TODO Auto-generated method stub
if(req.getRequestType().equals("请假")&&req.getNumber()<7)
System.out.println(this.name+"处理请假请求");
else
supervisor.handleRequest(req);
}
}
package org.ustc.chain;
public class Request {
private String RequestType;
private String RequestContent;
private int Number;
public String getRequestType() {
return RequestType;
}
public void setRequestType(String requestType) {
RequestType = requestType;
}
public String getRequestContent() {
return RequestContent;
}
public void setRequestContent(String requestContent) {
RequestContent = requestContent;
}
public int getNumber() {
return Number;
}
public void setNumber(int number) {
Number = number;
}
}
package org.ustc.chain;
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Manager jingli = new ProjectManager("经理");
Manager zongjian = new Director("总监");
Manager zongjinglin = new ChiefManager("总经理");
jingli.setSupervisor(zongjian);
zongjian.setSupervisor(zongjinglin);
Request req = new Request();
req.setNumber(50);
req.setRequestType("请假");
req.setNumber(10);
req.setRequestType("加薪");
jingli.handleRequest(req);
}
}