| Package | org.puremvc.as3.patterns.facade |
| Class | public class Facade |
| Implements | IFacade |
IFacade implementation.
In PureMVC, the Facade class assumes these
responsibilities:
Model, View
and Controller Singletons.IModel,
IView, & IController interfaces.Model,
View and Controller Singletons created.Commands and notifying ObserversExample usage:
import org.puremvc.as3.patterns.facade.∗;
import com.me.myapp.model.*;
import com.me.myapp.view.*;
import com.me.myapp.controller.*;
public class MyFacade extends 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 GO_COMMAND:String = "go";
// Override Singleton Factory method
public static function getInstance() : MyFacade {
if (instance == null) instance = new MyFacade();
return instance as MyFacade;
}
// optional initialization hook for Facade
override public function initializeFacade() : void {
super.initializeFacade();
// do any special subclass initialization here
}
// optional initialization hook for Controller
override public function initializeController() : void {
// call super to use the PureMVC Controller Singleton.
super.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
override public function initializeModel() : void {
// call super to use the PureMVC Model Singleton.
super.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
override public function initializeView() : void {
// call super to use the PureMVC View Singleton.
super.initializeView();
// Otherwise, if you're implmenting your own
// IView, then instead do:
// if ( view != null ) return;
// view = MyAppView.getInstance();
// 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.
}
}
See also
| Property | Defined by | ||
|---|---|---|---|
| controller : IController | Facade | ||
| instance : IFacade
[static]
| Facade | ||
| model : IModel | Facade | ||
| view : IView | Facade | ||
| Method | Defined by | ||
|---|---|---|---|
|
Facade()
Constructor.
| Facade | ||
|
[static]
Facade Singleton Factory method
| Facade | ||
|
hasCommand(notificationName:String):Boolean
Check if a Command is registered for a given Notification
| Facade | ||
|
hasMediator(mediatorName:String):Boolean
Check if a Mediator is registered or not
| Facade | ||
|
hasProxy(proxyName:String):Boolean
Check if a Proxy is registered
| Facade | ||
|
notifyObservers(notification:INotification):void
Notify
Observers. | Facade | ||
|
registerCommand(notificationName:String, commandClassRef:Class):void
Register an
ICommand with the Controller by Notification name. | Facade | ||
|
registerMediator(mediator:IMediator):void
Register a
IMediator with the View. | Facade | ||
|
registerProxy(proxy:IProxy):void
Register an
IProxy with the Model by name. | Facade | ||
|
removeCommand(notificationName:String):void
Remove a previously registered
ICommand to INotification mapping from the Controller. | Facade | ||
|
removeMediator(mediatorName:String):IMediator
Remove an
IMediator from the View. | Facade | ||
|
removeProxy(proxyName:String):IProxy
Remove an
IProxy from the Model by name. | Facade | ||
|
retrieveMediator(mediatorName:String):IMediator
Retrieve an
IMediator from the View. | Facade | ||
|
retrieveProxy(proxyName:String):IProxy
Retrieve an
IProxy from the Model by name. | Facade | ||
|
sendNotification(notificationName:String, body:Object = null, type:String = null):void
Create and send an
INotification. | Facade | ||
| Method | Defined by | ||
|---|---|---|---|
|
initializeController():void
Initialize the
Controller. | Facade | ||
|
initializeFacade():void
Initialize the Singleton
Facade instance. | Facade | ||
|
initializeModel():void
Initialize the
Model. | Facade | ||
|
initializeView():void
Initialize the
View. | Facade | ||
| Constant | Defined by | ||
|---|---|---|---|
| SINGLETON_MSG : String = "Facade Singleton already constructed!" | Facade | ||
| controller | property |
protected var controller:IController
| instance | property |
protected static var instance:IFacade
| model | property |
protected var model:IModel
| view | property |
protected var view:IView
| Facade | () | constructor |
public function Facade()Constructor.
This IFacade implementation is a Singleton,
so you should not call the constructor
directly, but instead call the static Singleton
Factory method Facade.getInstance()
— Error if Singleton instance has already been constructed
|
| getInstance | () | method |
public static function getInstance():IFacadeFacade Singleton Factory method
ReturnsIFacade —
the Singleton instance of the Facade
|
| hasCommand | () | method |
public function hasCommand(notificationName:String):BooleanCheck if a Command is registered for a given Notification
ParametersnotificationName:String |
Boolean — whether a Command is currently registered for the given notificationName.
|
| hasMediator | () | method |
public function hasMediator(mediatorName:String):BooleanCheck if a Mediator is registered or not
ParametersmediatorName:String |
Boolean — whether a Mediator is registered with the given mediatorName.
|
| hasProxy | () | method |
public function hasProxy(proxyName:String):BooleanCheck if a Proxy is registered
ParametersproxyName:String |
Boolean — whether a Proxy is currently registered with the given proxyName.
|
| initializeController | () | method |
protected function initializeController():void
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:
IController.Commands to register with the Controller at startup.. IController,
call super.initializeController() at the beginning of your
method, then register Commands.
| initializeFacade | () | method |
protected function initializeFacade():void
Initialize the Singleton Facade instance.
Called automatically by the constructor. Override in your
subclass to do any subclass specific initializations. Be
sure to call super.initializeFacade(), though.
| initializeModel | () | method |
protected function initializeModel():void
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:
IModel.Proxys to register with the Model that do not
retrieve a reference to the Facade at construction time.IModel,
call super.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.
| initializeView | () | method |
protected function initializeView():void
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:
IView.Observers to register with the ViewIView,
call super.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.
| notifyObservers | () | method |
public function notifyObservers(notification:INotification):void
Notify Observers.
This method is left public mostly for backward compatibility, and to allow you to send custom notification classes using the facade.
P> Usually you should just call sendNotification and pass the parameters, never having to construct the notification yourself. Parametersnotification:INotification — the INotification to have the View notify Observers of.
|
| registerCommand | () | method |
public function registerCommand(notificationName:String, commandClassRef:Class):void
Register an ICommand with the Controller by Notification name.
notificationName:String — the name of the INotification to associate the ICommand with
|
|
commandClassRef:Class — a reference to the Class of the ICommand
|
| registerMediator | () | method |
public function registerMediator(mediator:IMediator):void
Register a IMediator with the View.
mediator:IMediator — the name to associate with this IMediator
|
| registerProxy | () | method |
public function registerProxy(proxy:IProxy):void
Register an IProxy with the Model by name.
proxy:IProxy — the name of the IProxy.
|
| removeCommand | () | method |
public function removeCommand(notificationName:String):void
Remove a previously registered ICommand to INotification mapping from the Controller.
notificationName:String — the name of the INotification to remove the ICommand mapping for
|
| removeMediator | () | method |
public function removeMediator(mediatorName:String):IMediator
Remove an IMediator from the View.
mediatorName:String — name of the IMediator to be removed.
|
IMediator —
the IMediator that was removed from the View
|
| removeProxy | () | method |
public function removeProxy(proxyName:String):IProxy
Remove an IProxy from the Model by name.
proxyName:String — the IProxy to remove from the Model.
|
IProxy —
the IProxy that was removed from the Model
|
| retrieveMediator | () | method |
public function retrieveMediator(mediatorName:String):IMediator
Retrieve an IMediator from the View.
mediatorName:String |
IMediator —
the IMediator previously registered with the given mediatorName.
|
| retrieveProxy | () | method |
public function retrieveProxy(proxyName:String):IProxy
Retrieve an IProxy from the Model by name.
proxyName:String — the name of the proxy to be retrieved.
|
IProxy —
the IProxy instance previously registered with the given proxyName.
|
| sendNotification | () | method |
public function sendNotification(notificationName:String, body:Object = null, type:String = null):void
Create and send an INotification.
Keeps us from having to construct new notification instances in our implementation code.
ParametersnotificationName:String — the name of the notiification to send
|
|
body:Object (default = null) — the body of the notification (optional)
|
|
type:String (default = null) — the type of the notification (optional)
|
| SINGLETON_MSG | constant |
protected const SINGLETON_MSG:String = "Facade Singleton already constructed!"