class Command { // Fields private var receiver: Receiver ; // Constructors private function Command( receiver:Receiver ) { this.receiver = receiver; } // Methods public function Execute():Void{}; } // "Receiver" class Receiver { // Methods public function Action():Void { trace("Called Receiver.Action()"); } } // "Invoker" class Invoker { // Fields private var command:Command ; // Methods public function SetCommand( command:Command ):Void { this.command = command; } public function ExecuteCommand():Void { command.Execute(); } } // "ConcreteCommand" class ConcreteCommand extends Command { // Constructors public function ConcreteCommand(receiver:Receiver) { super(receiver); } // Methods public function Execute():Void { receiver.Action(); } } //client.fla // Create receiver, command, and invoker var r:Receiver = new Receiver(); var c:Command = new ConcreteCommand(r); var i:Invoker = new Invoker(); // Set and execute command i.SetCommand(c); i.ExecuteCommand(); //Called Receiver.Action()
栏目列表
Command模式
发布时间:2008-11-20
点击:
来源:本站原创
录入者:佚名
附件:
![]() ![]() |