A base Singleton Facade implementation.

Facade

Implements

Constructors

  • Constructor.

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

    Returns Facade

    Error if instance for this Singleton instance has already been constructed

Properties

controller?: IController

Reference to Controller

model?: IModel

Reference to Model

view?: IView

Reference to View

instance: IFacade

Singleton instance

SINGLETON_MSG: string = "Facade Singleton already constructed!"

Message Constants

Methods

  • Check if a Command is registered for a given Notification

    Parameters

    • notificationName: string

      The name of the notification to check.

    Returns boolean

    true if a command is registered for the notification; otherwise, false.

  • Check if a Mediator is registered or not

    Parameters

    • mediatorName: string

      The name of the mediator to check.

    Returns boolean

    true if a mediator is registered for the name; otherwise, false.

  • Check if a Proxy is registered

    Parameters

    • proxyName: string

      The name of the proxy to check.

    Returns boolean

    true if a proxy is registered for the name; otherwise, false.

  • 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 Controller.
    • You have Commands to register with the Controller at startup.`.

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

    Returns 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.

    Returns 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:

    • You wish to initialize a different Model.
    • 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 Model, 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 Notifications and thus will likely want to fetch a reference to the Facade during their construction.

    Returns 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:

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

    If you don't want to initialize a different View, call super.initializeView() at the beginning of your method, then register Mediator 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 Mediator instances will need to send Notifications and thus will likely want to fetch a reference to the Facade during their construction.

    Returns void

  • 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.

    Parameters

    • notification: INotification

      The notification to be sent to observers.

    Returns void

  • Register a Command with the Controller by Notification name. *

    Parameters

    • notificationName: string

      The name of the notification to associate with the command.

    • factory: (() => ICommand)

      A factory function that returns an instance of ICommand. This function is used to create the command.

    Returns void

  • Register a Mediator with the View.

    Parameters

    • mediator: IMediator

      The mediator instance to be registered.

    Returns void

  • Register a Proxy with the Model by name.

    Parameters

    • proxy: IProxy

      The proxy instance to be registered.

    Returns void

  • Remove a previously registered Command to Notification mapping from the Controller.

    Parameters

    • notificationName: string

      The name of the notification for which the command should be removed.

    Returns void

  • Remove a Mediator from the View.

    Parameters

    • mediatorName: string

      The name of the mediator to remove.

    Returns null | IMediator

    The removed mediator instance, or null if no such mediator exists.

  • Remove a Proxy from the Model by name.

    Parameters

    • proxyName: string

      The name of the proxy to remove.

    Returns null | IProxy

    The removed proxy instance, or null if no such proxy exists.

  • Retrieve a Proxy from the Model by name.

    Parameters

    • mediatorName: string

      The name of the mediator to retrieve.

    Returns null | IMediator

    The mediator instance associated with the given name, or null if no such mediator exists.

  • Retrieve a Proxy from the Model by name.

    Parameters

    • proxyName: string

      The name of the proxy to retrieve.

    Returns null | IProxy

    The proxy instance associated with the given name, or null if no such proxy exists.

  • Create and send an Notification.

    Keeps us from having to construct new notification instances in our implementation code.

    Parameters

    • notificationName: string

      The name of the notification to be sent.

    • Optionalbody: any

      Optional data to be included with the notification.

    • Optionaltype: string

      Optional type of the notification.

    Returns void

  • Facade Singleton Factory method

    Parameters

    • factory: (() => IFacade)

      A factory function that creates a new instance of the facade.

    Returns IFacade

    the Singleton instance of the Facade