Package puremvc :: Package patterns :: Module command :: Class MacroCommand
[hide private]
[frames] | no frames]

Class MacroCommand

source code

          object --+        
                   |        
interfaces.INotifier --+    
                       |    
       observer.Notifier --+
                           |
          object --+       |
                   |       |
interfaces.INotifier --+   |
                       |   |
     interfaces.ICommand --+
                           |
                          MacroCommand

A base ICommand implementation that executes other ICommands.

A MacroCommand maintains an list of ICommand Class references called <i>SubCommands</i>.

When execute is called, the MacroCommand instantiates and calls execute on each of its <i>SubCommands</i> turn. Each <i>SubCommand</i> will be passed a reference to the original INotification that was passed to the MacroCommand's execute method.

Unlike SimpleCommand, your subclass should not override execute, but instead, should override the initializeMacroCommand method, calling addSubCommand once for each <i>SubCommand</i> to be executed.


See Also:
Controller, Notification, SimpleCommand
Instance Methods [hide private]
 
__init__(self)
MacroCommand Constructor.
source code
 
initializeMacroCommand(self)
Initialize the MacroCommand.
source code
 
addSubCommand(self, commandClassRef)
Add a <i>SubCommand</i>.
source code
 
execute(self, notification)
Execute this MacroCommand's <i>SubCommands</i>.
source code

Inherited from observer.Notifier: initializeNotifier, sendNotification

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables [hide private]

Inherited from observer.Notifier: MULTITON_MSG

Properties [hide private]

Inherited from observer.Notifier: facade

Inherited from object: __class__

Method Details [hide private]

__init__(self)
(Constructor)

source code 

MacroCommand Constructor.

You should not need to define a constructor, instead, override the initializeMacroCommand method.

If your subclass does define a constructor, be sure to call super().

Overrides: object.__init__

initializeMacroCommand(self)

source code 

Initialize the MacroCommand.

In your subclass, override this method to initialize the MacroCommand's <i>SubCommand</i> list with ICommand class references like this:

   // Initialize MyMacroCommand
   function initializeMacroCommand( ) : void
   {
       addSubCommand( com.me.myapp.controller.FirstCommand );
       addSubCommand( com.me.myapp.controller.SecondCommand );
       addSubCommand( com.me.myapp.controller.ThirdCommand );
   }

Note that <i>SubCommand</i>s may be any ICommand implementor, MacroCommands or SimpleCommands are both acceptable.

addSubCommand(self, commandClassRef)

source code 

Add a <i>SubCommand</i>.

The <i>SubCommands</i> will be called in First In/First Out (FIFO) order.

Parameters:
  • commandClassRef - a reference to the Class of the ICommand.

execute(self, notification)

source code 

Execute this MacroCommand's <i>SubCommands</i>.

The <i>SubCommands</i> will be called in First In/First Out (FIFO) order.

Parameters:
  • notification - the INotification object to be passsed to each <i>SubCommand</i>.
Overrides: interfaces.ICommand.execute