休暇昇給(職責チェーンモデル)


学習ノート
 
ロールチェーンモードの構造と装飾モードの構造は同じです.
 
 
要求タイプ
public class Request {
	
	private String name;
	private String requestType;
	private int number;
	
	
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getRequestType() {
		return requestType;
	}
	public void setRequestType(String requestType) {
		this.requestType = requestType;
	}
	public int getNumber() {
		return number;
	}
	public void setNumber(int number) {
		this.number = number;
	}
	
	
	
}
 

管理する抽象クラス
 
   
public abstract class Manager {
	
	protected String name;
	// 
    protected Manager superior;
    
	public Manager(String name) {
	 
		this.name=name;
		 
	}
	
	// 
	public void SetSuperior(Manager superior){
		
		this.superior=superior;
	}
	// 
	abstract public void requestApplications(Request requset);
	
	public static void main(String[]args){
		
		CommonManager commonManager =new CommonManager("hyy");
		GeneralManager generalManager =new GeneralManager("ysen");
		Majordomo majordomo =new Majordomo("hdx");
		// 
		commonManager.SetSuperior(majordomo);
		majordomo.SetSuperior(generalManager);
		
		
		Request request = new  Request();
		request.setName("ysen");
		request.setRequestType(" ");
		request.setNumber(800);
		commonManager.requestApplications(request);
		
	}

}

管理するクラス
 
// 
public class GeneralManager extends Manager {

	public GeneralManager(String name) {
		super(name);
		 
	}

	@Override
	public void requestApplications(Request request) {
		
		if(request.getRequestType().equals(" ")&&request.getNumber()<=7){
			 
			 System.out.println(request.getName()+request.getRequestType()+request.getNumber()+" " );
			 
		 }else if(request.getRequestType().equals(" ")&&request.getNumber()<=800){
			 
			 System.out.println(request.getName()+request.getRequestType()+request.getNumber()+" " );
				
		 }
		 else{
			 if(this.superior!=null){
				 
				 this.superior.requestApplications(request);
			 }
			 
			 
		 }

	}

}

 

 

// 
public class Majordomo extends Manager {

	public Majordomo(String name) {
		super(name);
	 
	}

	@Override
	public void requestApplications(Request request) {
	 
		
	 if(request.getRequestType().equals(" ")&&   request.getNumber() <=5){
			 
			 System.out.println(request.getName()+request.getRequestType()+request.getNumber()+" " );
			 
		 }else{
			 if(this.superior!=null){
				 
				 this.superior.requestApplications(request);
			 }
			 
			 
		 }

	}

}

 

// 
public class CommonManager extends Manager {

	public CommonManager(String name) {
		super(name);
	 
	}

	@Override
	public void requestApplications(Request request) {
		
		 if(request.getRequestType().equals(" ")&& request.getNumber()<=2){
			 
			 System.out.println(request.getName()+request.getRequestType()+request.getNumber()+" " );
			 
		 }else{
			 if(this.superior!=null){
				 
				 this.superior.requestApplications(request);
			 }
			 
			 
		 }

	}

}