package Command;
/***
* 真正命令的执行者
* @author zw
*
*/
public class Receiver {
public void action() {
System.out.println("执行动作");
}
}
package Command;
public interface Command {
void execute();
}
class ConcreteCommand implements Command{
private Receiver receiver;
public ConcreteCommand(Receiver receiver) {
super();
this.receiver = receiver;
}
@Override
public void execute() {
// TODO Auto-generated method stub
receiver.action();
}
}
package Command;
/***
* 调用者和发起者
* @author zw
*
*/
public class Invoke {
private Command command;
public Invoke(Command command) {
super();
this.command = command;
}
public void call() {
command.execute();
}
}
package Command;
public class Client {
public static void main(String[] args) {
Receiver r = new Receiver();
Command command = new ConcreteCommand(r);
Invoke i = new Invoke(command);
i.call();
}
}