facade

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 13, 2023 License: BSD-3-Clause Imports: 6 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetInstance

func GetInstance(key string, factory func() interfaces.IFacade) interfaces.IFacade

GetInstance is a Facade Multiton factory method.

Facade Multiton Factory method

- parameter key: multitonKey

- parameter factory: reference that returns IFacade

- returns: the Multiton instance of the IFacade

func HasCore

func HasCore(key string) bool

HasCore Check if a Core is registered or not

- parameter key: the multiton key for the Core in question

- returns: whether a Core is registered with the given key.

func RemoveCore

func RemoveCore(key string)

RemoveCore Remove a Core.

Remove the Model, View, Controller and Facade instances for the given key.

- parameter key: multitonKey of the Core to remove

Types

type Facade

type Facade struct {
	Key string // The Multiton Key
	// contains filtered or unexported fields
}

Facade represents a base implementation of the Multiton pattern for IFacade. A base Multiton IFacade implementation.

func (*Facade) HasCommand

func (self *Facade) HasCommand(notificationName string) bool

HasCommand Check if a Command is registered for a given Notification

- parameter notificationName:

- returns: whether a Command is currently registered for the given notificationName.

func (*Facade) HasMediator

func (self *Facade) HasMediator(mediatorName string) bool

HasMediator Check if a Mediator is registered or not

- parameter mediatorName:

- returns: whether a Mediator is registered with the given mediatorName.

func (*Facade) HasProxy

func (self *Facade) HasProxy(proxyName string) bool

HasProxy Check if a Proxy is registered

- parameter proxyName:

- returns: whether a Proxy is currently registered with the given proxyName.

func (*Facade) InitializeController

func (self *Facade) InitializeController()

InitializeController 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 self.Facade.initializeController() at the beginning of your method, then register Commands.

func (*Facade) InitializeFacade

func (self *Facade) InitializeFacade()

InitializeFacade Initialize the Multiton Facade instance.

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

func (*Facade) InitializeModel

func (self *Facade) InitializeModel()

InitializeModel 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 self.Facade.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.

func (*Facade) InitializeNotifier

func (self *Facade) InitializeNotifier(key string)

InitializeNotifier Set the Multiton key for this facade instance.

Not called directly, but instead from the GetInstance when it is invoked.

func (*Facade) InitializeView

func (self *Facade) InitializeView()

InitializeView 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 self.Facade.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.

func (*Facade) NotifyObservers

func (self *Facade) NotifyObservers(notification interfaces.INotification)

NotifyObservers Notify Observers.

This method is left 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.

- parameter notification: the INotification to have the View notify Observers of.

func (*Facade) RegisterCommand

func (self *Facade) RegisterCommand(notificationName string, factory func() interfaces.ICommand)

RegisterCommand Register an ICommand with the Controller by Notification name.

- parameter notificationName: the name of the INotification to associate the ICommand with

- parameter factory: reference that returns ICommand

func (*Facade) RegisterMediator

func (self *Facade) RegisterMediator(mediator interfaces.IMediator)

RegisterMediator Register a IMediator with the View.

- parameter mediator: a reference to the IMediator

func (*Facade) RegisterProxy

func (self *Facade) RegisterProxy(proxy interfaces.IProxy)

RegisterProxy Register an IProxy with the Model by name.

- parameter proxy: the IProxy instance to be registered with the Model.

func (*Facade) RemoveCommand

func (self *Facade) RemoveCommand(notificationName string)

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

- parameter notificationName: the name of the INotification to remove the ICommand mapping for

func (*Facade) RemoveMediator

func (self *Facade) RemoveMediator(mediatorName string) interfaces.IMediator

RemoveMediator Remove an IMediator from the View.

- parameter mediatorName: name of the IMediator to be removed.

- returns: the IMediator that was removed from the View

func (*Facade) RemoveProxy

func (self *Facade) RemoveProxy(proxyName string) interfaces.IProxy

RemoveProxy Remove an IProxy from the Model by name.

- parameter proxyName: the IProxy to remove from the Model.

- returns: the IProxy that was removed from the Model

func (*Facade) RetrieveMediator

func (self *Facade) RetrieveMediator(mediatorName string) interfaces.IMediator

RetrieveMediator Retrieve an IMediator from the View.

- parameter mediatorName:

- returns: the IMediator previously registered with the given mediatorName.

func (*Facade) RetrieveProxy

func (self *Facade) RetrieveProxy(proxyName string) interfaces.IProxy

RetrieveProxy Retrieve an IProxy from the Model by name.

- parameter proxyName: the name of the proxy to be retrieved.

- returns: the IProxy instance previously registered with the given proxyName.

func (*Facade) SendNotification

func (self *Facade) SendNotification(notificationName string, body interface{}, _type string)

SendNotification Create and send an INotification.

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

- parameter notificationName: the name of the notiification to send

- parameter body: the body of the notification (optional)

- parameter _type: the type of the notification

type Notifier

type Notifier struct {
	Facade interfaces.IFacade
	Key    string // The Multiton Key for this app
}

Notifier A Base INotifier implementation.

MacroCommand, Command, Mediator and Proxy all have a need to send Notifications.

The INotifier interface provides a common method called sendNotification that relieves implementation code of the necessity to actually construct Notifications.

The Notifier class, which all of the above mentioned classes extend, provides an initialized reference to the Facade Multiton, which is required for the convenience method for sending Notifications, but also eases implementation as these classes have frequent Facade interactions and usually require access to the facade anyway.

NOTE: In the MultiCore version of the framework, there is one caveat to notifiers, they cannot send notifications or reach the facade until they have a valid multitonKey.

The multitonKey is set:

* on a Command when it is executed by the Controller

* on a Mediator is registered with the View

* on a Proxy is registered with the Model.

func (*Notifier) InitializeNotifier

func (self *Notifier) InitializeNotifier(key string)

InitializeNotifier Initialize this INotifier instance.

This is how a Notifier gets its multitonKey. Calls to sendNotification or to access the facade will fail until after this method has been called.

Mediators, Commands or Proxies may override this method in order to send notifications or access the Multiton Facade instance as soon as possible. They CANNOT access the facade in their constructors, since this method will not yet have been called.

- parameter key: the multitonKey for this INotifier to use

func (*Notifier) SendNotification

func (self *Notifier) SendNotification(notificationName string, body interface{}, _type string)

SendNotification Create and send an INotification.

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

- parameter notificationName: the name of the notification to send

- parameter body: the body of the notification (optional)

- parameter type: the _type of the notification

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL