Package puremvc :: Module core :: Class Controller
[hide private]
[frames] | no frames]

Class Controller

source code

            object --+    
                     |    
interfaces.IController --+
                         |
                        Controller

A Multiton IController implementation.

In PureMVC, the Controller class follows the 'Command and Controller' strategy, and assumes these responsibilities:

Remembering which ICommands are intended to handle which INotifications.

Registering itself as an IObserver with the View for each INotification that it has an ICommand mapping for.

Creating a new instance of the proper ICommand to handle a given INotification when notified by the View.

Calling the ICommand's execute method, passing in the INotification.

Your application must register ICommands with the Controller.

The simplest way is to subclass Facade, and use its initializeController method to add your registrations.


See Also:
View, Observer, Notification, SimpleCommand, MacroCommand
Instance Methods [hide private]
 
__init__(self, key)
Constructor.
source code
 
initializeController(self)
Initialize the Multiton Controller instance.
source code
 
executeCommand(self, note)
If an ICommand has previously been registered to handle a the given INotification, then it is executed.
source code
 
registerCommand(self, notificationName, commandClassRef)
Register a particular ICommand class as the handler for a particular INotification.
source code
 
hasCommand(self, notificationName)
Check if a Command is registered for a given Notification
source code
 
removeCommand(self, notificationName)
Remove a previously registered ICommand to INotification mapping.
source code

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

Class Methods [hide private]
 
removeController(cls, key)
Remove an IController instance
source code
 
getInstance(cls, key)
Controller Multiton Factory method.
source code
Class Variables [hide private]
  instanceMap = {}
Multiton error message
  MULTITON_MSG = 'Controller multiton instance for this key is a...
Instance Variables [hide private]
  view
Mapping of Notification names to Command Classes
  commandMap
The Multiton Key for this Core
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

removeController(cls, key)
Class Method

source code 

Remove an IController instance

Parameters:
  • key - of IController instance to remove

__init__(self, key)
(Constructor)

source code 

Constructor.

This IController implementation is a Multiton, so you should not call the constructor directly, but instead call the static Factory method, passing the unique key for this instance Controller.getInstance( multitonKey )

Raises:
  • MultitonError - if instance for this Multiton key has already been constructed
Overrides: object.__init__

initializeController(self)

source code 

Initialize the Multiton Controller instance.

Called automatically by the constructor.

Note that if you are using a subclass of View in your application, you should <i>also</i> subclass Controller and override the initializeController method in the following way:

   // ensure that the Controller is talking to my IView implementation
   public function initializeController(  ) : void
   {
       view = MyView.getInstance();
   }
Returns:
void

getInstance(cls, key)
Class Method

source code 

Controller Multiton Factory method.

Returns:
the Multiton instance of Controller

executeCommand(self, note)

source code 

If an ICommand has previously been registered to handle a the given INotification, then it is executed.

Parameters:
  • note - an INotification
Overrides: interfaces.IController.executeCommand

registerCommand(self, notificationName, commandClassRef)

source code 

Register a particular ICommand class as the handler for a particular INotification.

If an ICommand has already been registered to handle INotifications with this name, it is no longer used, the new ICommand is used instead.

The Observer for the new ICommand is only created if this the first time an ICommand has been registered for this Notification name.

Parameters:
  • notificationName - the name of the INotification
  • commandClassRef - the Class of the ICommand
Overrides: interfaces.IController.registerCommand

hasCommand(self, notificationName)

source code 

Check if a Command is registered for a given Notification

Parameters:
  • notificationName - the name of the INotification
Returns:
whether a Command is currently registered for the given notificationName.
Overrides: interfaces.IController.hasCommand

removeCommand(self, notificationName)

source code 

Remove a previously registered ICommand to INotification mapping.

Parameters:
  • notificationName - the name of the INotification to remove the ICommand mapping for
Overrides: interfaces.IController.removeCommand

Class Variable Details [hide private]

MULTITON_MSG

Value:
'Controller multiton instance for this key is already constructed!'