设计模式之命令(command)
?
public class CommandPattern {abstract class Command{Receiver receiver;public Command(Receiver receiver){this.receiver = receiver;}protected abstract void execute();}class ConcreteCommand extends Command{public ConcreteCommand(Receiver receiver) {super(receiver); }@Overrideprotected void execute() {receiver.action();}}//接收者,命令的具体内容class Receiver{public void action(){System.out.println("execute action method...");}}//调用命令并执行class Invoker{Command command;public Invoker(Command command){this.command = command;}public void executeCommand(){command.execute();}}public static void main(String[] args){CommandPattern cp = new CommandPattern();ConcreteCommand cc = cp.new ConcreteCommand(cp.new Receiver());Invoker invoker = cp.new Invoker(cc);invoker.executeCommand();}}
?http://www.360doc.com/content/10/0707/13/1720440_37423392.shtml
?