256 | Chapter 7: Command Pattern
Two Concrete Subcommands
To demonstrate a macro command, we will implement two concrete command
classes (ConcreteCommand1 and ConcreteCommand2) that use two receiver classes
(Receiver1 andReceiver2). These are shown in Example 7-8 through Example 7-11.
Example 7-7. IMacroCommand.as
package
{
public interface IMacroCommand extends ICommand {
function add(c:ICommand):void;
function remove(c:ICommand):void;
}
}
Example 7-8. ConcreteCommand1.as
package {
class ConcreteCommand1 implements ICommand
{
var receiver:Receiver1;
public function ConcreteCommand1(rec:Receiver1):void
{
this.receiver = rec;
}
public function execute( ):void
{
receiver.action1( );
}
}
}
Example 7-9. ConcreteCommand2.as
package {
class ConcreteCommand2 implements ICommand
{
var receiver:Receiver2;
public function ConcreteCommand2(rec:Receiver2):void
{
this.receiver = rec;
}
public function execute( ):void
{
receiver.action2( );
}
}
}