package com.test.DPs.XingWei.Command;
/**
* 行为型:Command-命令 外观:作用面为 对象
*
* 用途:将一个请求封装为一个对象,从而使你可用不同的请求对客户进行参数化;
* 将请求排队或记录请求日志,以及支持可撤销操作。
*
* 理解:三种关系:发送者 命令 接收者,解耦。发送者关心接收者所做操作结果,而忽略命令实现的细节。
*/
interface Command{
void exe();
}
class MyCommand implements Command{
private Receiver receiver;
public MyCommand(Receiver receiver){
this.receiver = receiver;
}
@Override
public void exe(){
receiver.action();
}
}
class Receiver{
public void action(){
System.out.println("command received!");
}
}
class Invoker{ //master soldier command
private Command command;
public Invoker(Command command){
this.command = command;
}
public void action(){
command.exe();
}
}