Class Facade
public class Facade extends java.lang.Object implements IFacade
A base Singleton IFacade implementation.
In PureMVC, the Facade class assumes these
 responsibilities:
- Initializing the 
Model,ViewandControllerSingletons. - Providing all the methods defined by the 
IModel, IView, & IControllerinterfaces. - Providing the ability to override the specific 
Model,ViewandControllerSingletons created. - Providing a single point of contact to the application for
 registering 
Commandsand notifyingObservers 
Example usage:
  
	import org.puremvc.as3.patterns.facade.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 final String GO_COMMAND = "go";
		// Override Singleton Factory method
		public synchronized static IFacade getInstance(Supplier<IFacade> facadeSupplier) {
			if(instance == null) instance = facadeSupplier.get();
			return instance;
		}
		// optional initialization hook for Facade
		public void initializeFacade() {
			super.initializeFacade();
			// do any special subclass initialization here
		}
		// optional initialization hook for Controller
		public void initializeController()  {
			// 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(() -> new MyAppController());
			// do any special subclass initialization here
			// such as registering Commands
			registerCommand( GO_COMMAND, () -> new com.me.myapp.controller.GoCommand() )
		}
		// optional initialization hook for Model
		public void initializeModel() {
			// 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(() -> new MyAppModel());
			// 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.
			registerProxy( 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 void initializeView() {
			// 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(() -> new MyAppView());
			// 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:
 Model,View,Controller,Notification,Mediator,Proxy,SimpleCommand,MacroCommand
- 
Field Summary
Fields Modifier and Type Field Description protected IControllercontrollerprotected static IFacadeinstanceprotected IModelmodelprotected java.lang.StringSINGLETON_MSGprotected IViewview - 
Constructor Summary
Constructors Constructor Description Facade()Constructor. - 
Method Summary
Modifier and Type Method Description static IFacadegetInstance(java.util.function.Supplier<IFacade> factory)Facade Singleton Factory methodbooleanhasCommand(java.lang.String notificationName)Check if a Command is registered for a given NotificationbooleanhasMediator(java.lang.String mediatorName)Check if a Mediator is registered or notbooleanhasProxy(java.lang.String proxyName)Check if a Proxy is registeredprotected voidinitializeController()Initialize theController.protected voidinitializeFacade()Initialize the SingletonFacadeinstance.protected voidinitializeModel()Initialize theModel.protected voidinitializeView()Initialize theView.voidnotifyObservers(INotification notification)NotifyObservers.voidregisterCommand(java.lang.String notificationName, java.util.function.Supplier<ICommand> commandSupplier)Register anICommandwith theControllerby Notification name.voidregisterMediator(IMediator mediator)Register aIMediatorwith theView.voidregisterProxy(IProxy proxy)Register anIProxywith theModelby name.voidremoveCommand(java.lang.String notificationName)Remove a previously registeredICommandtoINotificationmapping from the Controller.IMediatorremoveMediator(java.lang.String mediatorName)Remove anIMediatorfrom theView.IProxyremoveProxy(java.lang.String proxyName)Remove anIProxyfrom theModelby name.IMediatorretrieveMediator(java.lang.String mediatorName)Retrieve anIMediatorfrom theView.IProxyretrieveProxy(java.lang.String proxyName)Retrieve anIProxyfrom theModelby name.voidsendNotification(java.lang.String notificationName)Create and send anINotification.voidsendNotification(java.lang.String notificationName, java.lang.Object body)Create and send anINotification.voidsendNotification(java.lang.String notificationName, java.lang.Object body, java.lang.String type)Create and send anINotification. 
- 
Field Details
- 
controller
 - 
model
 - 
view
 - 
instance
 - 
SINGLETON_MSG
protected final java.lang.String SINGLETON_MSG- See Also:
 - Constant Field Values
 
 
 - 
 - 
Constructor Details
- 
Facade
public Facade()Constructor.
This
IFacadeimplementation is a Singleton, so you should not call the constructor directly, but instead call the static Singleton Factory methodFacade.getInstance()- Throws:
 java.lang.Error- Error if Singleton instance has already been constructed
 
 - 
 - 
Method Details
- 
initializeFacade
protected void initializeFacade()Initialize the Singleton
Facadeinstance.Called automatically by the constructor. Override in your subclass to do any subclass specific initializations. Be sure to call
super.initializeFacade(), though. - 
getInstance
Facade Singleton Factory method
- Parameters:
 factory- facade Supplier Function- Returns:
 - the Singleton instance of the Facade
 
 - 
initializeController
protected void initializeController()Initialize the
Controller.Called by the
initializeFacademethod. Override this method in your subclass ofFacadeif one or both of the following are true:-  You wish to initialize a different 
IController. -  You have 
Commandsto register with theControllerat startup. 
If you don't want to initialize a different
IController, callsuper.initializeController()at the beginning of your method, then registerCommands. -  You wish to initialize a different 
 - 
initializeModel
protected void initializeModel()Initialize the
Model.Called by the
initializeFacademethod. Override this method in your subclass ofFacadeif 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, callsuper.initializeModel()at the beginning of your method, then registerProxys.Note: This method is rarely overridden; in practice you are more likely to use a
Commandto create and registerProxys with theModel, sinceProxys with mutable data will likely need to sendINotifications and thus will likely want to fetch a reference to theFacadeduring their construction. -  You wish to initialize a different 
 - 
initializeView
protected void initializeView()Initialize the
View.Called by the
initializeFacademethod. Override this method in your subclass ofFacadeif one or both of the following are true:-  You wish to initialize a different 
IView. -  You have 
Observersto register with theView 
If you don't want to initialize a different
IView, callsuper.initializeView()at the beginning of your method, then registerIMediatorinstances.Note: This method is rarely overridden; in practice you are more likely to use a
Commandto create and registerMediators with theView, sinceIMediatorinstances will need to sendINotifications and thus will likely want to fetch a reference to theFacadeduring their construction. -  You wish to initialize a different 
 - 
registerCommand
public void registerCommand(java.lang.String notificationName, java.util.function.Supplier<ICommand> commandSupplier)Register an
ICommandwith theControllerby Notification name.- Specified by:
 registerCommandin interfaceIFacade- Parameters:
 notificationName- the name of theINotificationto associate theICommandwithcommandSupplier- a reference to the Supplier Function of theICommand
 - 
removeCommand
public void removeCommand(java.lang.String notificationName)Remove a previously registered
ICommandtoINotificationmapping from the Controller.- Specified by:
 removeCommandin interfaceIFacade- Parameters:
 notificationName- the name of theINotificationto remove theICommandmapping for
 - 
hasCommand
public boolean hasCommand(java.lang.String notificationName)Check if a Command is registered for a given Notification
- Specified by:
 hasCommandin interfaceIFacade- Parameters:
 notificationName- notification name- Returns:
 - whether a Command is currently registered for the given 
notificationName. 
 - 
registerProxy
Register an
IProxywith theModelby name.- Specified by:
 registerProxyin interfaceIFacade- Parameters:
 proxy- theIProxyinstance to be registered with theModel.
 - 
retrieveProxy
Retrieve an
IProxyfrom theModelby name.- Specified by:
 retrieveProxyin interfaceIFacade- Parameters:
 proxyName- the name of the proxy to be retrieved.- Returns:
 - the 
IProxyinstance previously registered with the givenproxyName. 
 - 
removeProxy
Remove an
IProxyfrom theModelby name.- Specified by:
 removeProxyin interfaceIFacade- Parameters:
 proxyName- theIProxyto remove from theModel.- Returns:
 - the 
IProxythat was removed from theModel 
 - 
hasProxy
public boolean hasProxy(java.lang.String proxyName)Check if a Proxy is registered
 - 
registerMediator
Register a
IMediatorwith theView.- Specified by:
 registerMediatorin interfaceIFacade- Parameters:
 mediator- a reference to theIMediator
 - 
retrieveMediator
Retrieve an
IMediatorfrom theView.- Specified by:
 retrieveMediatorin interfaceIFacade- Parameters:
 mediatorName- mediator name- Returns:
 - the 
IMediatorpreviously registered with the givenmediatorName. 
 - 
removeMediator
Remove an
IMediatorfrom theView.- Specified by:
 removeMediatorin interfaceIFacade- Parameters:
 mediatorName- name of theIMediatorto be removed.- Returns:
 - the 
IMediatorthat was removed from theView 
 - 
hasMediator
public boolean hasMediator(java.lang.String mediatorName)Check if a Mediator is registered or not
- Specified by:
 hasMediatorin interfaceIFacade- Parameters:
 mediatorName- mediator name- Returns:
 - whether a Mediator is registered with the given 
mediatorName. 
 - 
sendNotification
public void sendNotification(java.lang.String notificationName, java.lang.Object body, java.lang.String type)Create and send an
INotification.Keeps us from having to construct new notification instances in our implementation code.
- Specified by:
 sendNotificationin interfaceINotifier- Parameters:
 notificationName- the name of the notiification to sendbody- the body of the notificationtype- the type of the notification
 - 
sendNotification
public void sendNotification(java.lang.String notificationName, java.lang.Object body)Create and send an
INotification.Keeps us from having to construct new notification instances in our implementation code.
- Specified by:
 sendNotificationin interfaceINotifier- Parameters:
 notificationName- the name of the notiification to sendbody- the body of the notification
 - 
sendNotification
public void sendNotification(java.lang.String notificationName)Create and send an
INotification.Keeps us from having to construct new notification instances in our implementation code.
- Specified by:
 sendNotificationin interfaceINotifier- Parameters:
 notificationName- the name of the notiification to send
 - 
notifyObservers
Notify
Observers.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.
- Specified by:
 notifyObserversin interfaceIFacade- Parameters:
 notification- theINotificationto have theViewnotifyObserversof.
 
 -