首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件开发 >

设计方式之命令(command)

2012-10-30 
设计模式之命令(command)?public class CommandPattern {abstract class Command{Receiver receiverpubli

设计模式之命令(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

?

热点排行