PureMVC.Patterns.Facade Class Reference

A base Singleton IFacade implementation. More...

Inheritance diagram for PureMVC.Patterns.Facade:

PureMVC.Interfaces.IFacade PureMVC.Interfaces.INotifier

List of all members.

Public Member Functions

void RegisterProxy (IProxy proxy)
 Register an IProxy with the Model by name.
IProxy RetrieveProxy (string proxyName)
 Retrieve a IProxy from the Model by name.
IProxy RemoveProxy (string proxyName)
 Remove an IProxy instance from the Model by name.
bool HasProxy (string proxyName)
 Check if a Proxy is registered.
void RegisterCommand (string notificationName, Type commandType)
 Register an ICommand with the Controller.
void RemoveCommand (string notificationName)
 Remove a previously registered ICommand to INotification mapping from the Controller.
bool HasCommand (string notificationName)
 Check if a Command is registered for a given Notification.
void RegisterMediator (IMediator mediator)
 Register an IMediator instance with the View.
IMediator RetrieveMediator (string mediatorName)
 Retrieve an IMediator instance from the View.
IMediator RemoveMediator (string mediatorName)
 Remove a IMediator instance from the View.
bool HasMediator (string mediatorName)
 Check if a Mediator is registered or not.
void NotifyObservers (INotification notification)
 Notify Observers of an INotification.
void SendNotification (string notificationName)
 Send an INotification.
void SendNotification (string notificationName, object body)
 Send an INotification.
void SendNotification (string notificationName, object body, string type)
 Send an INotification.

Protected Member Functions

 Facade ()
virtual void InitializeFacade ()
 Initialize the Singleton Facade instance.
virtual void InitializeController ()
 Initialize the Controller.
virtual void InitializeModel ()
 Initialize the Model.
virtual void InitializeView ()
 Initialize the View.

Protected Attributes

IController m_controller
IModel m_model
 Private reference to the Model.
IView m_view
 Private reference to the View.

Static Protected Attributes

static volatile IFacade m_instance
 The Singleton Facade Instance.
static readonly object m_staticSyncRoot = new object()
 Used for locking the instance calls.

Properties

static IFacade Instance [get]
 Facade Singleton Factory method. This method is thread safe.


Detailed Description

A base Singleton IFacade implementation.

In PureMVC, the Facade class assumes these responsibilities:

        using PureMVC.Patterns;

        using com.me.myapp.model;
        using com.me.myapp.view;
        using com.me.myapp.controller;

        public class MyFacade : Facade
        {
                // Notification constants. The Facade is the ideal
                // location for these constants, since any part
                // of the application participating in PureMVC 
                // Observer Notification will know the Facade.
                public static const string GO_COMMAND = "go";

            // we aren't allowed to initialize new instances from outside this class
            protected MyFacade() {}

            // we must specify the type of instance
            static MyFacade()
            {
                instance = new MyFacade();
            }

                // Override Singleton Factory method 
                public new static MyFacade getInstance() {
                        return instance as MyFacade;
                }

                // optional initialization hook for Facade
                public override void initializeFacade() {
                        base.initializeFacade();
                        // do any special subclass initialization here
                }

                // optional initialization hook for Controller
                public override void initializeController() {
                        // call base to use the PureMVC Controller Singleton. 
                        base.initializeController();

                        // Otherwise, if you're implmenting your own
                        // IController, then instead do:
                        // if ( controller != null ) return;
                        // controller = MyAppController.getInstance();

                        // do any special subclass initialization here
                        // such as registering Commands
                        registerCommand( GO_COMMAND, com.me.myapp.controller.GoCommand )
                }

                // optional initialization hook for Model
                public override void initializeModel() {
                        // call base to use the PureMVC Model Singleton. 
                        base.initializeModel();

                        // Otherwise, if you're implmenting your own
                        // IModel, then instead do:
                        // if ( model != null ) return;
                        // model = MyAppModel.getInstance();

                        // do any special subclass initialization here
                        // such as creating and registering Model proxys
                        // that don't require a facade reference at
                        // construction time, such as fixed type lists
                        // that never need to send Notifications.
                        regsiterProxy( new USStateNamesProxy() );

                        // CAREFUL: Can't reference Facade instance in constructor 
                        // of new Proxys from here, since this step is part of
                        // Facade construction!  Usually, Proxys needing to send 
                        // notifications are registered elsewhere in the app 
                        // for this reason.
                }

                // optional initialization hook for View
                public override void initializeView() {
                        // call base to use the PureMVC View Singleton. 
                        base.initializeView();

                        // Otherwise, if you're implmenting your own
                        // IView, then instead do:
                        // if ( view != null ) return;
                        // view = MyAppView.Instance;

                        // do any special subclass initialization here
                        // such as creating and registering Mediators
                        // that do not need a Facade reference at construction
                        // time.
                        registerMediator( new LoginMediator() ); 

                        // CAREFUL: Can't reference Facade instance in constructor 
                        // of new Mediators from here, since this is a step
                        // in Facade construction! Usually, all Mediators need 
                        // receive notifications, and are registered elsewhere in 
                        // the app for this reason.
                }
        }

PureMVC.Core.Model PureMVC.Core.View PureMVC.Core.Controller PureMVC.Patterns.Notification PureMVC.Patterns.Mediator PureMVC.Patterns.Proxy PureMVC.Patterns.SimpleCommand PureMVC.Patterns.MacroCommand


Constructor & Destructor Documentation

PureMVC.Patterns.Facade.Facade (  )  [protected]

Constructor that initializes the Facade

This IFacade implementation is a Singleton, so you should not call the constructor directly, but instead call the static Singleton Factory method Facade.Instance


Member Function Documentation

bool PureMVC.Patterns.Facade.HasCommand ( string  notificationName  ) 

Check if a Command is registered for a given Notification.

Parameters:
notificationName The name of the INotification to check for.
Returns:
whether a Command is currently registered for the given notificationName.
This method is thread safe and needs to be thread safe in all implementations.

Implements PureMVC.Interfaces.IFacade.

bool PureMVC.Patterns.Facade.HasMediator ( string  mediatorName  ) 

Check if a Mediator is registered or not.

Parameters:
mediatorName The name of the IMediator instance to check for
Returns:
whether a Mediator is registered with the given
mediatorName
.
This method is thread safe and needs to be thread safe in all implementations.

Implements PureMVC.Interfaces.IFacade.

bool PureMVC.Patterns.Facade.HasProxy ( string  proxyName  ) 

Check if a Proxy is registered.

Parameters:
proxyName The name of the IProxy instance to check for
Returns:
whether a Proxy is currently registered with the given proxyName.
This method is thread safe and needs to be thread safe in all implementations.

Implements PureMVC.Interfaces.IFacade.

virtual void PureMVC.Patterns.Facade.InitializeController (  )  [protected, virtual]

Initialize the Controller.

Called by the initializeFacade method. Override this method in your subclass of Facade if one or both of the following are true:

  • You wish to initialize a different IController
  • You have Commands to register with the Controller at startup

If you don't want to initialize a different IController, call base.initializeController() at the beginning of your method, then register Commands

virtual void PureMVC.Patterns.Facade.InitializeFacade (  )  [protected, virtual]

Initialize the Singleton Facade instance.

Called automatically by the constructor. Override in your subclass to do any subclass specific initializations. Be sure to call base.initializeFacade(), though

virtual void PureMVC.Patterns.Facade.InitializeModel (  )  [protected, virtual]

Initialize the Model.

Called by the initializeFacade method. Override this method in your subclass of Facade if one or both of the following are true:

  • You wish to initialize a different IModel
  • You have Proxys to register with the Model that do not retrieve a reference to the Facade at construction time

If you don't want to initialize a different IModel, call base.initializeModel() at the beginning of your method, then register Proxys

Note: This method is rarely overridden; in practice you are more likely to use a Command to create and register Proxys with the Model, since Proxys with mutable data will likely need to send INotifications and thus will likely want to fetch a reference to the Facade during their construction

virtual void PureMVC.Patterns.Facade.InitializeView (  )  [protected, virtual]

Initialize the View.

Called by the initializeFacade method. Override this method in your subclass of Facade if one or both of the following are true:

  • You wish to initialize a different IView
  • You have Observers to register with the View

If you don't want to initialize a different IView, call base.initializeView() at the beginning of your method, then register IMediator instances

Note: This method is rarely overridden; in practice you are more likely to use a Command to create and register Mediators with the View, since IMediator instances will need to send INotifications and thus will likely want to fetch a reference to the Facade during their construction

void PureMVC.Patterns.Facade.NotifyObservers ( INotification  notification  ) 

Notify Observers of an INotification.

This method is left public mostly for backward compatibility, and to allow you to send custom notification classes using the facade. Usually you should just call sendNotification and pass the parameters, never having to construct the notification yourself.

Parameters:
notification The INotification to have the View notify observers of
This method is thread safe and needs to be thread safe in all implementations.

Implements PureMVC.Interfaces.IFacade.

void PureMVC.Patterns.Facade.RegisterCommand ( string  notificationName,
Type  commandType 
)

Register an ICommand with the Controller.

Parameters:
notificationName The name of the INotification to associate the ICommand with.
commandType A reference to the Type of the ICommand
This method is thread safe and needs to be thread safe in all implementations.

Implements PureMVC.Interfaces.IFacade.

void PureMVC.Patterns.Facade.RegisterMediator ( IMediator  mediator  ) 

Register an IMediator instance with the View.

Parameters:
mediator A reference to the IMediator instance
This method is thread safe and needs to be thread safe in all implementations.

Implements PureMVC.Interfaces.IFacade.

void PureMVC.Patterns.Facade.RegisterProxy ( IProxy  proxy  ) 

Register an IProxy with the Model by name.

Parameters:
proxy The IProxy to be registered with the Model
This method is thread safe and needs to be thread safe in all implementations.

Implements PureMVC.Interfaces.IFacade.

void PureMVC.Patterns.Facade.RemoveCommand ( string  notificationName  ) 

Remove a previously registered ICommand to INotification mapping from the Controller.

Parameters:
notificationName TRemove a previously registered ICommand to INotification mapping from the Controller.
This method is thread safe and needs to be thread safe in all implementations.

Implements PureMVC.Interfaces.IFacade.

IMediator PureMVC.Patterns.Facade.RemoveMediator ( string  mediatorName  ) 

Remove a IMediator instance from the View.

Parameters:
mediatorName The name of the IMediator instance to be removed
This method is thread safe and needs to be thread safe in all implementations.

Implements PureMVC.Interfaces.IFacade.

IProxy PureMVC.Patterns.Facade.RemoveProxy ( string  proxyName  ) 

Remove an IProxy instance from the Model by name.

Parameters:
proxyName The IProxy to remove from the Model
This method is thread safe and needs to be thread safe in all implementations.

Implements PureMVC.Interfaces.IFacade.

IMediator PureMVC.Patterns.Facade.RetrieveMediator ( string  mediatorName  ) 

Retrieve an IMediator instance from the View.

Parameters:
mediatorName The name of the IMediator instance to retrieve
Returns:
The IMediator previously registered with the given mediatorName
This method is thread safe and needs to be thread safe in all implementations.

Implements PureMVC.Interfaces.IFacade.

IProxy PureMVC.Patterns.Facade.RetrieveProxy ( string  proxyName  ) 

Retrieve a IProxy from the Model by name.

Parameters:
proxyName The name of the IProxy instance to be retrieved
Returns:
The IProxy previously regisetered by proxyName with the Model
This method is thread safe and needs to be thread safe in all implementations.

Implements PureMVC.Interfaces.IFacade.

void PureMVC.Patterns.Facade.SendNotification ( string  notificationName,
object  body,
string  type 
)

Send an INotification.

Parameters:
notificationName The name of the notification to send
body The body of the notification
type The type of the notification
Keeps us from having to construct new notification instances in our implementation code This method is thread safe and needs to be thread safe in all implementations.

Implements PureMVC.Interfaces.INotifier.

void PureMVC.Patterns.Facade.SendNotification ( string  notificationName,
object  body 
)

Send an INotification.

Parameters:
notificationName The name of the notification to send
body The body of the notification
Keeps us from having to construct new notification instances in our implementation code This method is thread safe and needs to be thread safe in all implementations.

Implements PureMVC.Interfaces.INotifier.

void PureMVC.Patterns.Facade.SendNotification ( string  notificationName  ) 

Send an INotification.

Parameters:
notificationName The name of the notiification to send
Keeps us from having to construct new notification instances in our implementation code This method is thread safe and needs to be thread safe in all implementations.

Implements PureMVC.Interfaces.INotifier.


Member Data Documentation

Private reference to the Controller

volatile IFacade PureMVC.Patterns.Facade.m_instance [static, protected]

The Singleton Facade Instance.

Private reference to the Model.

readonly object PureMVC.Patterns.Facade.m_staticSyncRoot = new object() [static, protected]

Used for locking the instance calls.

Private reference to the View.


Property Documentation

IFacade PureMVC.Patterns.Facade.Instance [static, get]

Facade Singleton Factory method. This method is thread safe.


The documentation for this class was generated from the following file:

Generated on Thu Jan 1 16:26:46 2009 for PureMVC by  doxygen 1.5.8