烤羊肉串__命令模式_简单、专注、可依赖。_百度空间

package com.ding.shejimoshi.Command;

abstract class Command {

protected Receiver receiver;

public Command (Receiver receiver){
  
   this.receiver=receiver;
  
}


abstract public void Execute();


}

package com.ding.shejimoshi.Command;

public class Receiver {
public void Action(){
  
   System.out.println("执行请求!");
  
}

}
package com.ding.shejimoshi.Command;

public class ConcreteCommand extends Command{

public ConcreteCommand (Receiver receiver){
   super(receiver);
  
  
}

public void Execute(){
  
   receiver.Action();
}

}
package com.ding.shejimoshi.Command;

public class Invoker {


private Command command;

public void SetCommand(Command command){
  
   this.command=command;
}
public void ExecuteCommand(){
  
   command.Execute();
  
}








}

package com.ding.shejimoshi.Command;

public class CommandMain {

/**
* @param args
*/
public static void main(String[] args) {
   // TODO 自动生成方法存根
   Receiver r=new Receiver();
   Command c=new ConcreteCommand(r);
   Invoker i=new Invoker();
   i.SetCommand(c);
   i.ExecuteCommand();
  

}

}

优点 有利于顺序的执行,第二 容易记录

第三 容易撤销请求 和可新建请求



郑重声明:资讯 【烤羊肉串__命令模式_简单、专注、可依赖。_百度空间】由 发布,版权归原作者及其所在单位,其原创性以及文中陈述文字和内容未经(企业库qiyeku.com)证实,请读者仅作参考,并请自行核实相关内容。若本文有侵犯到您的版权, 请你提供相关证明及申请并与我们联系(qiyeku # qq.com)或【在线投诉】,我们审核后将会尽快处理。
—— 相关资讯 ——