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

type Controller

source code

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

A Singleton 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]
 
initializeController(self)
Initialize the Singleton 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
Static Methods [hide private]
 
__new__(cls, *args, **kwargs)
This IController implementation is a Singleton, so you should not call the constructor directly, but instead call the static Singleton method Controller.getInstance()
source code
 
getInstance()
Controller Singleton Static method.
source code
Class Variables [hide private]
  instance = None
  view = None
  commandMap = None
Method Details [hide private]

__new__(cls, *args, **kwargs)
Static Method

source code 

This IController implementation is a Singleton, so you should not call the constructor directly, but instead call the static Singleton method Controller.getInstance()

Overrides: object.__new__

getInstance()
Static Method

source code 

Controller Singleton Static method.

Returns:
the Singleton instance of Controller

initializeController(self)

source code 

Initialize the Singleton Controller instance.

Called automatically by the constructor.

Note that if you are using a subclass of View in your application, you will need to initialize the view property

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 regisered 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