http://www.cnblogs.com/java-my-life/archive/2012/06/01/2526972.html

-
public class Client {
-
public static void main(String[] args) {
-
-
Receiver receiver = new Receiver();
-
-
Command command = new ConcreteCommand(receiver);
-
-
Invoker invoker = new Invoker(command);
-
-
invoker.action();
-
}
-
}
-
-
class Receiver {
-
-
-
-
public void action() {
-
System.out.println("执行操作");
-
}
-
}
-
-
interface Command {
-
-
-
-
void execute();
-
}
-
-
class ConcreteCommand implements Command {
-
-
private Receiver receiver = null;
-
-
-
-
-
public ConcreteCommand(Receiver receiver) {
-
this.receiver = receiver;
-
}
-
-
@Override
-
public void execute() {
-
-
receiver.action();
-
}
-
-
}
-
-
class Invoker {
-
-
-
-
private Command command = null;
-
-
-
-
-
public Invoker(Command command) {
-
this.command = command;
-
}
-
-
-
-
-
public void action() {
-
-
command.execute();
-
}
-
}
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29254281/viewspace-2135676/
,如需转载,请注明出处,否则将追究法律责任。