命令模式:将“请求”封装成对象,以便使用不同的请求、队列或者日志来参数化其他对象。命令模式也支持可撤销的操作。
命令者将对象动作和接收者包进对象中,
public interface Command{
public void excute();
}
public class LightOnCommand implements Command{
Light light;
public LightOnCommand(Light light){
this.light = light;
}
public void execute()
{
light.on();
}
}
public class SimpleRemoteControl(){
Command slot;
public SimpleRemoteControl(){}
public void setCommand(Command command){
slot = command;
}
public void buttonWasPressed(){
slot.execute();
}
}
最后欢迎大家访问我的个人网站: 1024s