Minimalist Example: Macro Commands | 257
The Concrete Macro Command
We will now develop a macro command that implements theIMacroCommandinter-
face. The implementation is straightforward as Example 7-12 shows; it pushes com-
mands into thecommandObjectListarray in theadd( )method, and executes them in
sequence in theexecute( ) method.
Example 7-10. Receiver1.as
package {
class Receiver1 {
public function action1( ) {
trace("Receiver 1: doing action 1");
}
}
}
Example 7-11. Receiver2.as
package {
class Receiver2 {
public function action2( ) {
trace("Receiver 2: doing action 2");
}
}
}
Example 7-12. ConcreteMacroCommand.as
package
{
class ConcreteMacroCommand implements IMacroCommand
{
var commandObjectList:Array;
public function ConcreteMacroCommand( )
{
this.commandObjectList = new Array( );
}
public function add(c:ICommand):void
{
commandObjectList.push(c);
}
public function remove(c:ICommand):void
{
for (var i:int = 0; i < commandObjectList.length; i++)
{