diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5922f2e --- /dev/null +++ b/.gitignore @@ -0,0 +1,23 @@ +# If you prefer the allow list template instead of the deny list, see community template: +# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore +# +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ + +# Go workspace file +go.work +.idea/ +.DS_Store \ No newline at end of file diff --git a/README.md b/README.md index fc37143..1dacd00 100755 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ PureMVC is a lightweight framework for creating applications based upon the clas ## Installation ``` -require github.com/puremvc/puremvc-go-multicore-framework v1.0.0 +require github.com/puremvc/puremvc-go-multicore-framework v1.1.0 ``` ## Utilities @@ -21,7 +21,7 @@ require github.com/puremvc/puremvc-go-multicore-framework v1.0.0 * [Windows](https://en.wikipedia.org/wiki/Microsoft_Windows) ## Status -Production - [Version 1.0](https://github.com/PureMVC/puremvc-go-multicore-framework/blob/master/VERSION) +Production - [Version 1.1](https://github.com/PureMVC/puremvc-go-multicore-framework/blob/master/VERSION) ## License * PureMVC MultiCore Framework for Go - Copyright © 2019 [Saad Shams](https://www.linkedin.com/in/muizz/) diff --git a/VERSION b/VERSION index 64684ff..45324db 100644 --- a/VERSION +++ b/VERSION @@ -1,10 +1,12 @@ PureMVC MultiCore Framework for Go -------------------------------------------------------------------------- -Release Date: 04/25/19 +Release Date: 12/12/23 Platform: Go Version: 1 - Revision: 0 + Revision: 1 Minor: 0 Author: Saad Shams -------------------------------------------------------------------------- 1.0 - Initial release. + +1.1 - Updated to use Go 1.21. Minor Updates. diff --git a/go.mod b/go.mod index e37b952..d0dfb22 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ module github.com/puremvc/puremvc-go-multicore-framework -go 1.12 +go 1.21 diff --git a/src/core/controller/Controller.go b/src/core/controller/Controller.go index a12392f..2738940 100755 --- a/src/core/controller/Controller.go +++ b/src/core/controller/Controller.go @@ -16,7 +16,7 @@ import ( ) /* -A Multiton IController implementation. +Controller A Multiton IController implementation. In PureMVC, the Controller class follows the 'Command and Controller' strategy, and assumes these @@ -48,39 +48,39 @@ var instanceMap = map[string]interfaces.IController{} // The Multiton Controller var instanceMapMutex sync.RWMutex // instanceMap Mutex /* - Controller Multiton Factory method. +GetInstance Controller Multiton Factory method. - - parameter key: multitonKey +- parameter key: multitonKey - - parameter controllerFunc: reference that returns IController +- parameter factory reference that returns IController - - returns: the Multiton instance +- returns: the Multiton instance */ -func GetInstance(key string, controllerFunc func() interfaces.IController) interfaces.IController { +func GetInstance(key string, factory func() interfaces.IController) interfaces.IController { instanceMapMutex.Lock() defer instanceMapMutex.Unlock() if instanceMap[key] == nil { - instanceMap[key] = controllerFunc() + instanceMap[key] = factory() instanceMap[key].InitializeController() } return instanceMap[key] } /* - Initialize the Singleton Controller instance. +InitializeController Initialize the Singleton Controller instance. - Called automatically by the GetInstance. +Called automatically by the GetInstance. - Note that if you are using a subclass of View - in your application, you should also subclass Controller - and override the InitializeController method in the - following way: +Note that if you are using a subclass of View +in your application, you should also subclass Controller +and override the InitializeController method in the +following way: - func (self *MyController) InitializeController() { - self.commandMap = map[string]func() interfaces.ICommand{} - self.view = MyView.GetInstance(self.Key, func() interfaces.IView { return &MyView{Key: self.Key} }) - } + func (self *MyController) InitializeController() { + self.commandMap = map[string]func() interfaces.ICommand{} + self.view = MyView.GetInstance(self.Key, func() interfaces.IView { return &MyView{Key: self.Key} }) + } */ func (self *Controller) InitializeController() { self.commandMap = map[string]func() interfaces.ICommand{} @@ -88,55 +88,55 @@ func (self *Controller) InitializeController() { } /* - If an ICommand has previously been registered - to handle a the given INotification, then it is executed. +ExecuteCommand If an ICommand has previously been registered +to handle a the given INotification, then it is executed. - - parameter note: an INotification +- parameter note: an INotification */ func (self *Controller) ExecuteCommand(notification interfaces.INotification) { self.commandMapMutex.RLock() defer self.commandMapMutex.RUnlock() - var commandFunc = self.commandMap[notification.Name()] - if commandFunc == nil { + var factory = self.commandMap[notification.Name()] + if factory == nil { return } - commandInstance := commandFunc() + commandInstance := factory() commandInstance.InitializeNotifier(self.Key) commandInstance.Execute(notification) } /* - Register a particular ICommand class as the handler - for a particular INotification. +RegisterCommand Register a particular ICommand class as the handler +for a particular INotification. - If an ICommand has already been registered to - handle INotifications with this name, it is no longer - used, the new ICommand is used instead. +If an ICommand has already been registered to +handle INotifications with this name, it is no longer +used, the new ICommand is used instead. - The Observer for the new ICommand is only created if this the - first time an ICommand has been regisered for this Notification name. +The Observer for the new ICommand is only created if this the +first time an ICommand has been regisered for this Notification name. - - parameter notificationName: the name of the INotification +- parameter notificationName: the name of the INotification - - parameter commandFunc: reference that returns ICommand +- parameter factory: reference that returns ICommand */ -func (self *Controller) RegisterCommand(notificationName string, commandFunc func() interfaces.ICommand) { +func (self *Controller) RegisterCommand(notificationName string, factory func() interfaces.ICommand) { self.commandMapMutex.Lock() defer self.commandMapMutex.Unlock() if self.commandMap[notificationName] == nil { self.view.RegisterObserver(notificationName, &observer.Observer{Notify: self.ExecuteCommand, Context: self}) } - self.commandMap[notificationName] = commandFunc + self.commandMap[notificationName] = factory } /* - Check if a Command is registered for a given Notification +HasCommand Check if a Command is registered for a given Notification - - parameter notificationName: +- parameter notificationName: - - returns: whether a Command is currently registered for the given notificationName. +- returns: whether a Command is currently registered for the given notificationName. */ func (self *Controller) HasCommand(notificationName string) bool { self.commandMapMutex.RLock() @@ -146,9 +146,9 @@ func (self *Controller) HasCommand(notificationName string) bool { } /* - Remove a previously registered ICommand to INotification mapping. +RemoveCommand Remove a previously registered ICommand to INotification mapping. - - parameter notificationName: the name of the INotification to remove the ICommand mapping for +- parameter notificationName: the name of the INotification to remove the ICommand mapping for */ func (self *Controller) RemoveCommand(notificationName string) { self.commandMapMutex.Lock() @@ -161,9 +161,9 @@ func (self *Controller) RemoveCommand(notificationName string) { } /* - Remove an IController instance +RemoveController Remove an IController instance - - parameter multitonKey: of IController instance to remove +- parameter multitonKey: of IController instance to remove */ func RemoveController(key string) { instanceMapMutex.Lock() diff --git a/src/core/model/Model.go b/src/core/model/Model.go index ea95449..386cf37 100755 --- a/src/core/model/Model.go +++ b/src/core/model/Model.go @@ -14,7 +14,7 @@ import ( ) /* -A Multiton IModel implementation. +Model A Multiton IModel implementation. In PureMVC, the Model class provides access to model objects (Proxies) by named lookup. @@ -41,41 +41,41 @@ var instanceMap = map[string]interfaces.IModel{} // The Multiton Model instanceM var instanceMapMutex sync.RWMutex // instanceMapMutex for thread safety /* - Model Multiton Factory method. +GetInstance Model Multiton Factory method. - - parameter key: multitonKey +- parameter key: multitonKey - - parameter modelFunc: reference that returns IModel +- parameter factory: reference that returns IModel - - returns: the instance returned by the passed modelFunc +- returns: the instance returned by the passed factory */ -func GetInstance(key string, modelFunc func() interfaces.IModel) interfaces.IModel { +func GetInstance(key string, factory func() interfaces.IModel) interfaces.IModel { instanceMapMutex.Lock() defer instanceMapMutex.Unlock() if instanceMap[key] == nil { - instanceMap[key] = modelFunc() + instanceMap[key] = factory() instanceMap[key].InitializeModel() } return instanceMap[key] } /* - Initialize the Model instance. +InitializeModel Initialize the Model instance. - Called automatically by the GetInstance, this - is your opportunity to initialize the Multiton - instance in your subclass without overriding the - constructor. +Called automatically by the GetInstance, this +is your opportunity to initialize the Multiton +instance in your subclass without overriding the +constructor. */ func (self *Model) InitializeModel() { self.proxyMap = map[string]interfaces.IProxy{} } /* - Register an IProxy with the Model. +RegisterProxy Register an IProxy with the Model. - - parameter proxy: an IProxy to be held by the Model. +- parameter proxy: an IProxy to be held by the Model. */ func (self *Model) RegisterProxy(proxy interfaces.IProxy) { self.proxyMapMutex.Lock() @@ -87,25 +87,25 @@ func (self *Model) RegisterProxy(proxy interfaces.IProxy) { } /* - Retrieve an IProxy from the Model. +RetrieveProxy Retrieve an IProxy from the Model. - - parameter proxyName: +- parameter proxyName: - - returns: the IProxy instance previously registered with the given proxyName. +- returns: the IProxy instance previously registered with the given proxyName. */ func (self *Model) RetrieveProxy(proxyName string) interfaces.IProxy { - self.proxyMapMutex.RLock(); + self.proxyMapMutex.RLock() defer self.proxyMapMutex.RUnlock() return self.proxyMap[proxyName] } /* - Remove an IProxy from the Model. +RemoveProxy Remove an IProxy from the Model. - - parameter proxyName: name of the IProxy instance to be removed. +- parameter proxyName: name of the IProxy instance to be removed. - - returns: the IProxy that was removed from the Model +- returns: the IProxy that was removed from the Model */ func (self *Model) RemoveProxy(proxyName string) interfaces.IProxy { self.proxyMapMutex.Lock() @@ -120,11 +120,11 @@ func (self *Model) RemoveProxy(proxyName string) interfaces.IProxy { } /* - Check if a Proxy is registered +HasProxy Check if a Proxy is registered - - parameter proxyName: +- parameter proxyName: - - returns: whether a Proxy is currently registered with the given proxyName. +- returns: whether a Proxy is currently registered with the given proxyName. */ func (self *Model) HasProxy(proxyName string) bool { self.proxyMapMutex.RLock() @@ -134,9 +134,9 @@ func (self *Model) HasProxy(proxyName string) bool { } /* - Remove an IModel instance +RemoveModel Remove an IModel instance - - parameter multitonKey: of IModel instance to remove +- parameter multitonKey: of IModel instance to remove */ func RemoveModel(key string) { instanceMapMutex.Lock() diff --git a/src/core/view/View.go b/src/core/view/View.go index 478a698..d84a853 100755 --- a/src/core/view/View.go +++ b/src/core/view/View.go @@ -14,15 +14,15 @@ import ( "sync" ) -/** -A Multiton IView implementation. +/* +View A Multiton IView implementation. In PureMVC, the View class assumes these responsibilities: * Maintain a cache of IMediator instances. * Provide methods for registering, retrieving, and removing IMediators. -* Notifiying IMediators when they are registered or removed. +* Notifying IMediators when they are registered or removed. * Managing the observer lists for each INotification in the application. @@ -44,32 +44,32 @@ var instanceMap = map[string]interfaces.IView{} // The Multiton View instanceMap var instanceMapMutex = sync.RWMutex{} // instanceMapMutex /* - View Multiton Factory method. +GetInstance View Multiton Factory method. - - parameter key: multitonKey +- parameter key: multitonKey - - parameter viewFunc: reference that returns IView +- parameter factory: reference that returns IView - - returns: the Multiton instance returned by executing the passed viewFunc +- returns: the Multiton instance returned by executing the passed factory */ -func GetInstance(key string, viewFunc func() interfaces.IView) interfaces.IView { +func GetInstance(key string, factory func() interfaces.IView) interfaces.IView { instanceMapMutex.Lock() defer instanceMapMutex.Unlock() if instanceMap[key] == nil { - instanceMap[key] = viewFunc() + instanceMap[key] = factory() instanceMap[key].InitializeView() } return instanceMap[key] } /* - Initialize the Multiton View instance. +InitializeView Initialize the Multiton View instance. - Called automatically by the GetInstance, this - is your opportunity to initialize the Multiton - instance in your subclass without overriding the - constructor. +Called automatically by the GetInstance, this +is your opportunity to initialize the Multiton +instance in your subclass without overriding the +constructor. */ func (self *View) InitializeView() { self.mediatorMap = map[string]interfaces.IMediator{} @@ -77,12 +77,12 @@ func (self *View) InitializeView() { } /* - Register an IObserver to be notified - of INotifications with a given name. +RegisterObserver Register an IObserver to be notified +of INotifications with a given name. - - parameter notificationName: the name of the INotifications to notify this IObserver of +- parameter notificationName: the name of the INotifications to notify this IObserver of - - parameter observer: the IObserver to register +- parameter observer: the IObserver to register */ func (self *View) RegisterObserver(notificationName string, observer interfaces.IObserver) { self.observerMapMutex.Lock() @@ -96,13 +96,13 @@ func (self *View) RegisterObserver(notificationName string, observer interfaces. } /* - Notify the IObservers for a particular INotification. +NotifyObservers Notify the IObservers for a particular INotification. - All previously attached IObservers for this INotification's - list are notified and are passed a reference to the INotification in - the order in which they were registered. +All previously attached IObservers for this INotification's +list are notified and are passed a reference to the INotification in +the order in which they were registered. - - parameter notification: the INotification to notify IObservers of. +- parameter notification: the INotification to notify IObservers of. */ func (self *View) NotifyObservers(notification interfaces.INotification) { self.observerMapMutex.RLock() @@ -127,11 +127,11 @@ func (self *View) NotifyObservers(notification interfaces.INotification) { } /* - Remove the observer for a given notifyContext from an observer list for a given Notification name. +RemoveObserver Remove the observer for a given notifyContext from an observer list for a given Notification name. - - parameter notificationName: which observer list to remove from +- parameter notificationName: which observer list to remove from - - parameter notifyContext: remove the observer with this object as its notifyContext +- parameter notifyContext: remove the observer with this object as its notifyContext */ func (self *View) RemoveObserver(notificationName string, notifyContext interface{}) { self.observerMapMutex.Lock() @@ -158,19 +158,19 @@ func (self *View) RemoveObserver(notificationName string, notifyContext interfac } /* - Register an IMediator instance with the View. +RegisterMediator Register an IMediator instance with the View. - Registers the IMediator so that it can be retrieved by name, - and further interrogates the IMediator for its - INotification interests. +Registers the IMediator so that it can be retrieved by name, +and further interrogates the IMediator for its +INotification interests. - If the IMediator returns any INotification - names to be notified about, an Observer is created encapsulating - the IMediator instance's handleNotification method - and registering it as an Observer for all INotifications the - IMediator is interested in. +If the IMediator returns any INotification +names to be notified about, an Observer is created encapsulating +the IMediator instance's handleNotification method +and registering it as an Observer for all INotifications the +IMediator is interested in. - - parameter mediator: a reference to the IMediator instance +- parameter mediator: a reference to the IMediator instance */ func (self *View) RegisterMediator(mediator interfaces.IMediator) { self.mediatorMapMutex.Lock() @@ -191,7 +191,7 @@ func (self *View) RegisterMediator(mediator interfaces.IMediator) { // Register Mediator as an observer for each notification of interests if len(interests) > 0 { - // Create Observer referencing this mediator's handlNotification method + // Create Observer referencing this mediator's handleNotification method observer := &observer.Observer{Notify: mediator.HandleNotification, Context: mediator} // Register Mediator as Observer for its list of Notification interests @@ -205,11 +205,11 @@ func (self *View) RegisterMediator(mediator interfaces.IMediator) { } /* - Retrieve an IMediator from the View. +RetrieveMediator Retrieve an IMediator from the View. - - parameter mediatorName: the name of the IMediator instance to retrieve. +- parameter mediatorName: the name of the IMediator instance to retrieve. - - returns: the IMediator instance previously registered with the given mediatorName. +- returns: the IMediator instance previously registered with the given mediatorName. */ func (self *View) RetrieveMediator(mediatorName string) interfaces.IMediator { self.mediatorMapMutex.RLock() @@ -219,11 +219,11 @@ func (self *View) RetrieveMediator(mediatorName string) interfaces.IMediator { } /* - Remove an IMediator from the View. +RemoveMediator Remove an IMediator from the View. - - parameter mediatorName: name of the IMediator instance to be removed. +- parameter mediatorName: name of the IMediator instance to be removed. - - returns: the IMediator that was removed from the View +- returns: the IMediator that was removed from the View */ func (self *View) RemoveMediator(mediatorName string) interfaces.IMediator { self.mediatorMapMutex.Lock() @@ -252,11 +252,11 @@ func (self *View) RemoveMediator(mediatorName string) interfaces.IMediator { } /* - Check if a Mediator is registered or not +HasMediator Check if a Mediator is registered or not - - parameter mediatorName: +- parameter mediatorName: - - returns: whether a Mediator is registered with the given mediatorName. +- returns: whether a Mediator is registered with the given mediatorName. */ func (self *View) HasMediator(mediatorName string) bool { self.mediatorMapMutex.RLock() @@ -266,9 +266,9 @@ func (self *View) HasMediator(mediatorName string) bool { } /* - Remove an IView instance +RemoveView Remove an IView instance - - parameter multitonKey: of IView instance to remove +- parameter multitonKey: of IView instance to remove */ func RemoveView(key string) { instanceMapMutex.Lock() diff --git a/src/interfaces/ICommand.go b/src/interfaces/ICommand.go index 9d115cb..24f161d 100755 --- a/src/interfaces/ICommand.go +++ b/src/interfaces/ICommand.go @@ -9,7 +9,7 @@ package interfaces /* -The interface definition for a PureMVC Command. +ICommand The interface definition for a PureMVC Command. */ type ICommand interface { INotifier diff --git a/src/interfaces/IController.go b/src/interfaces/IController.go index 8560518..9e469fc 100755 --- a/src/interfaces/IController.go +++ b/src/interfaces/IController.go @@ -9,7 +9,7 @@ package interfaces /* -The interface definition for a PureMVC Controller. +IController The interface definition for a PureMVC Controller. In PureMVC, an IController implementor follows the 'Command and Controller' strategy, and @@ -34,9 +34,9 @@ type IController interface { for a particular INotification. - parameter notificationName: the name of the INotification - - parameter commandFunc: reference that returns ICommand + - parameter factory: reference that returns ICommand */ - RegisterCommand(notificationName string, commandFunc func() ICommand) + RegisterCommand(notificationName string, factory func() ICommand) /* Execute the ICommand previously registered as the diff --git a/src/interfaces/IFacade.go b/src/interfaces/IFacade.go index 229a8db..aa81876 100755 --- a/src/interfaces/IFacade.go +++ b/src/interfaces/IFacade.go @@ -9,7 +9,7 @@ package interfaces /* -The interface definition for a PureMVC Facade. +IFacade The interface definition for a PureMVC Facade. The Facade Pattern suggests providing a single class to act as a central point of communication @@ -37,12 +37,12 @@ type IFacade interface { InitializeController() /* - Initialize the Model. + Initialize the Model. */ InitializeModel() /* - Initialize the View. + Initialize the View. */ InitializeView() @@ -50,9 +50,9 @@ type IFacade interface { Register an ICommand with the Controller. - parameter noteName: the name of the INotification to associate the ICommand with. - - parameter commandFunc: reference that returns ICommand + - parameter factory: reference that returns ICommand */ - RegisterCommand(notificationName string, commandFunc func() ICommand) + RegisterCommand(notificationName string, factory func() ICommand) /* Remove a previously registered ICommand to INotification mapping from the Controller. diff --git a/src/interfaces/IMediator.go b/src/interfaces/IMediator.go index 2a1b841..5fbcb6d 100755 --- a/src/interfaces/IMediator.go +++ b/src/interfaces/IMediator.go @@ -9,7 +9,7 @@ package interfaces /* -The interface definition for a PureMVC Mediator. +IMediator The interface definition for a PureMVC Mediator. In PureMVC, IMediator implementors assume these responsibilities: diff --git a/src/interfaces/IModel.go b/src/interfaces/IModel.go index 7c4a642..821221a 100755 --- a/src/interfaces/IModel.go +++ b/src/interfaces/IModel.go @@ -9,7 +9,7 @@ package interfaces /* -The interface definition for a PureMVC Model. +IModel The interface definition for a PureMVC Model. In PureMVC, IModel implementors provide access to IProxy objects by named lookup. diff --git a/src/interfaces/INotification.go b/src/interfaces/INotification.go index 6115e1c..03017e3 100755 --- a/src/interfaces/INotification.go +++ b/src/interfaces/INotification.go @@ -9,7 +9,7 @@ package interfaces /* -The interface definition for a PureMVC Notification. +INotification The interface definition for a PureMVC Notification. PureMVC does not rely upon underlying event models such as the one provided with Flash, and ActionScript 3 does diff --git a/src/interfaces/INotifier.go b/src/interfaces/INotifier.go index 1985bee..e547497 100755 --- a/src/interfaces/INotifier.go +++ b/src/interfaces/INotifier.go @@ -9,7 +9,7 @@ package interfaces /* -The interface definition for a PureMVC Notifier. +INotifier The interface definition for a PureMVC Notifier. MacroCommand, Command, Mediator and Proxy all have a need to send Notifications. diff --git a/src/interfaces/IObserver.go b/src/interfaces/IObserver.go index eb6611a..b637d47 100755 --- a/src/interfaces/IObserver.go +++ b/src/interfaces/IObserver.go @@ -9,7 +9,7 @@ package interfaces /* -The interface definition for a PureMVC Observer. +IObserver The interface definition for a PureMVC Observer. In PureMVC, IObserver implementors assume these responsibilities: diff --git a/src/interfaces/IProxy.go b/src/interfaces/IProxy.go index c0a392a..1417c13 100755 --- a/src/interfaces/IProxy.go +++ b/src/interfaces/IProxy.go @@ -9,7 +9,7 @@ package interfaces /* -The interface definition for a PureMVC Proxy. +IProxy The interface definition for a PureMVC Proxy. In PureMVC, IProxy implementors assume these responsibilities: @@ -43,7 +43,7 @@ type IProxy interface { SetData(data interface{}) /* - Get the data object + Get the data object */ GetData() interface{} diff --git a/src/interfaces/IView.go b/src/interfaces/IView.go index bf2df16..6b30ed7 100755 --- a/src/interfaces/IView.go +++ b/src/interfaces/IView.go @@ -9,7 +9,7 @@ package interfaces /* -The interface definition for a PureMVC View. +IView The interface definition for a PureMVC View. In PureMVC, IView implementors assume these responsibilities: diff --git a/src/patterns/command/MacroCommand.go b/src/patterns/command/MacroCommand.go index 366b4a7..2f7f730 100755 --- a/src/patterns/command/MacroCommand.go +++ b/src/patterns/command/MacroCommand.go @@ -14,9 +14,9 @@ import ( ) /* -A base ICommand implementation that executes other ICommands. +MacroCommand A base ICommand implementation that executes other ICommands. -A MacroCommand maintains an list of +A MacroCommand maintains a list of ICommand Class references called SubCommands. When execute is called, the MacroCommand @@ -38,54 +38,54 @@ type MacroCommand struct { } /* - Initialize the MacroCommand. - - In your subclass, override this method to - initialize the MacroCommand's *SubCommand* - list with func references like - this: - - // Initialize MyMacroCommand - func (self *MacroCommandTestCommand) InitializeMacroCommand() { - self.AddSubCommand(func() interfaces.ICommand { return &FirstCommand{} }) - self.AddSubCommand(func() interfaces.ICommand { return &SecondCommand{} }) - self.AddSubCommand(func() interfaces.ICommand { return &ThirdCommand{} }) - } - - Note that SubCommands may be any func returning ICommand - implementor, MacroCommands or SimpleCommands are both acceptable. +InitializeMacroCommand Initialize the MacroCommand. + +In your subclass, override this method to +initialize the MacroCommand's *SubCommand* +list with func references like +this: + + // Initialize MyMacroCommand + func (self *MacroCommandTestCommand) InitializeMacroCommand() { + self.AddSubCommand(func() interfaces.ICommand { return &FirstCommand{} }) + self.AddSubCommand(func() interfaces.ICommand { return &SecondCommand{} }) + self.AddSubCommand(func() interfaces.ICommand { return &ThirdCommand{} }) + } + +Note that SubCommands may be any func returning ICommand +implementor, MacroCommands or SimpleCommands are both acceptable. */ func (self *MacroCommand) InitializeMacroCommand() { } /* - Add a SubCommand. +AddSubCommand Add a SubCommand. - The SubCommands will be called in First In/First Out (FIFO) - order. +The SubCommands will be called in First In/First Out (FIFO) +order. - - parameter func: reference that returns ICommand. +- parameter factory: reference that returns ICommand. */ -func (self *MacroCommand) AddSubCommand(commandFunc func() interfaces.ICommand) { - self.SubCommands = append(self.SubCommands, commandFunc) +func (self *MacroCommand) AddSubCommand(factory func() interfaces.ICommand) { + self.SubCommands = append(self.SubCommands, factory) } /* - Execute this MacroCommand's SubCommands. +Execute this MacroCommand's SubCommands. - The SubCommands will be called in First In/First Out (FIFO) - order. +The SubCommands will be called in First In/First Out (FIFO) +order. - - parameter notification: the INotification object to be passsed to each SubCommand. +- parameter notification: the INotification object to be passsed to each SubCommand. */ func (self *MacroCommand) Execute(notification interfaces.INotification) { self.InitializeMacroCommand() for len(self.SubCommands) > 0 { - commandClassRef := self.SubCommands[0] + factory := self.SubCommands[0] self.SubCommands = self.SubCommands[1:] - commandInstance := commandClassRef() + commandInstance := factory() commandInstance.InitializeNotifier(self.Key) commandInstance.Execute(notification) } diff --git a/src/patterns/command/SimpleCommand.go b/src/patterns/command/SimpleCommand.go index 5a39901..e5b9c44 100755 --- a/src/patterns/command/SimpleCommand.go +++ b/src/patterns/command/SimpleCommand.go @@ -14,7 +14,7 @@ import ( ) /* -A base ICommand implementation. +SimpleCommand A base ICommand implementation. Your subclass should override the execute method where your business logic will handle the INotification. @@ -24,14 +24,14 @@ type SimpleCommand struct { } /* - Fulfill the use-case initiated by the given INotification. +Execute Fulfill the use-case initiated by the given INotification. - In the Command Pattern, an application use-case typically - begins with some user action, which results in an INotification being broadcast, which - is handled by business logic in the execute method of an - ICommand. +In the Command Pattern, an application use-case typically +begins with some user action, which results in an INotification being broadcast, which +is handled by business logic in the execute method of an +ICommand. - - parameter notification: the INotification to handle. +- parameter notification: the INotification to handle. */ func (self *SimpleCommand) Execute(notification interfaces.INotification) { diff --git a/src/patterns/facade/Facade.go b/src/patterns/facade/Facade.go index 442d9dc..cbe5178 100755 --- a/src/patterns/facade/Facade.go +++ b/src/patterns/facade/Facade.go @@ -18,6 +18,7 @@ import ( ) /* +Facade represents a base implementation of the Multiton pattern for IFacade. A base Multiton IFacade implementation. */ type Facade struct { @@ -31,31 +32,33 @@ var instanceMap = map[string]interfaces.IFacade{} // The Multiton Facade instanc var instanceMapMutex = sync.RWMutex{} // instanceMapMutex for the instance /* - Facade Multiton Factory method +GetInstance is a Facade Multiton factory method. - - parameter key: multitonKey +# Facade Multiton Factory method - - parameter facadeFunc: reference that returns IFacade +- parameter key: multitonKey - - returns: the Multiton instance of the IFacade +- parameter factory: reference that returns IFacade + +- returns: the Multiton instance of the IFacade */ -func GetInstance(key string, facadeFunc func() interfaces.IFacade) interfaces.IFacade { +func GetInstance(key string, factory func() interfaces.IFacade) interfaces.IFacade { instanceMapMutex.Lock() defer instanceMapMutex.Unlock() if instanceMap[key] == nil { - instanceMap[key] = facadeFunc() + instanceMap[key] = factory() instanceMap[key].InitializeFacade() } return instanceMap[key] } /* - Initialize the Multiton Facade instance. +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. +Called automatically by the GetInstance. Override in your +subclass to do any subclass specific initializations. Be +sure to call self.Facade.initializeFacade(), though. */ func (self *Facade) InitializeFacade() { self.InitializeModel() @@ -64,238 +67,238 @@ func (self *Facade) InitializeFacade() { } /* - Initialize the Controller. +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: +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 wish to initialize a different IController. - * You have Commands to register with the Controller at startup. +* 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. +If you don't want to initialize a different IController, +call self.Facade.initializeController() at the beginning of your +method, then register Commands. */ func (self *Facade) InitializeController() { self.controller = controller.GetInstance(self.Key, func() interfaces.IController { return &controller.Controller{Key: self.Key} }) } /* - Initialize the Model. +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: +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 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. +* 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. +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. +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 (self *Facade) InitializeModel() { self.model = model.GetInstance(self.Key, func() interfaces.IModel { return &model.Model{Key: self.Key} }) } /* - Initialize the View. +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: +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 wish to initialize a different IView. - * You have Observers to register with the View +* 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. +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. +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 (self *Facade) InitializeView() { self.view = view.GetInstance(self.Key, func() interfaces.IView { return &view.View{Key: self.Key} }) } /* - Register an ICommand with the Controller by Notification name. +RegisterCommand Register an ICommand with the Controller by Notification name. - - parameter notificationName: the name of the INotification to associate the ICommand with +- parameter notificationName: the name of the INotification to associate the ICommand with - - parameter commandFunc: reference that returns ICommand +- parameter factory: reference that returns ICommand */ -func (self *Facade) RegisterCommand(notificationName string, commandFunc func() interfaces.ICommand) { - self.controller.RegisterCommand(notificationName, commandFunc) +func (self *Facade) RegisterCommand(notificationName string, factory func() interfaces.ICommand) { + self.controller.RegisterCommand(notificationName, factory) } /* - Remove a previously registered ICommand to INotification mapping from the Controller. +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 +- parameter notificationName: the name of the INotification to remove the ICommand mapping for */ func (self *Facade) RemoveCommand(notificationName string) { self.controller.RemoveCommand(notificationName) } /* - Check if a Command is registered for a given Notification +HasCommand Check if a Command is registered for a given Notification - - parameter notificationName: +- parameter notificationName: - - returns: whether a Command is currently registered for the given notificationName. +- returns: whether a Command is currently registered for the given notificationName. */ func (self *Facade) HasCommand(notificationName string) bool { return self.controller.HasCommand(notificationName) } /* - Register an IProxy with the Model by name. +RegisterProxy Register an IProxy with the Model by name. - - parameter proxy: the IProxy instance to be registered with the Model. +- parameter proxy: the IProxy instance to be registered with the Model. */ func (self *Facade) RegisterProxy(proxy interfaces.IProxy) { self.model.RegisterProxy(proxy) } /* - Retrieve an IProxy from the Model by name. +RetrieveProxy Retrieve an IProxy from the Model by name. - - parameter proxyName: the name of the proxy to be retrieved. +- parameter proxyName: the name of the proxy to be retrieved. - - returns: the IProxy instance previously registered with the given proxyName. +- returns: the IProxy instance previously registered with the given proxyName. */ func (self *Facade) RetrieveProxy(proxyName string) interfaces.IProxy { return self.model.RetrieveProxy(proxyName) } /* - Remove an IProxy from the Model by name. +RemoveProxy Remove an IProxy from the Model by name. - - parameter proxyName: the IProxy to remove from the Model. +- parameter proxyName: the IProxy to remove from the Model. - - returns: the IProxy that was removed from the Model +- returns: the IProxy that was removed from the Model */ func (self *Facade) RemoveProxy(proxyName string) interfaces.IProxy { return self.model.RemoveProxy(proxyName) } /* - Check if a Proxy is registered +HasProxy Check if a Proxy is registered - - parameter proxyName: +- parameter proxyName: - - returns: whether a Proxy is currently registered with the given proxyName. +- returns: whether a Proxy is currently registered with the given proxyName. */ func (self *Facade) HasProxy(proxyName string) bool { return self.model.HasProxy(proxyName) } /* - Register a IMediator with the View. +RegisterMediator Register a IMediator with the View. - - parameter mediator: a reference to the IMediator +- parameter mediator: a reference to the IMediator */ func (self *Facade) RegisterMediator(mediator interfaces.IMediator) { self.view.RegisterMediator(mediator) } /* - Retrieve an IMediator from the View. +RetrieveMediator Retrieve an IMediator from the View. - - parameter mediatorName: +- parameter mediatorName: - - returns: the IMediator previously registered with the given mediatorName. +- returns: the IMediator previously registered with the given mediatorName. */ func (self *Facade) RetrieveMediator(mediatorName string) interfaces.IMediator { return self.view.RetrieveMediator(mediatorName) } /* - Remove an IMediator from the View. +RemoveMediator Remove an IMediator from the View. - - parameter mediatorName: name of the IMediator to be removed. +- parameter mediatorName: name of the IMediator to be removed. - - returns: the IMediator that was removed from the View +- returns: the IMediator that was removed from the View */ func (self *Facade) RemoveMediator(mediatorName string) interfaces.IMediator { return self.view.RemoveMediator(mediatorName) } /* - Check if a Mediator is registered or not +HasMediator Check if a Mediator is registered or not - - parameter mediatorName: +- parameter mediatorName: - - returns: whether a Mediator is registered with the given mediatorName. +- returns: whether a Mediator is registered with the given mediatorName. */ func (self *Facade) HasMediator(mediatorName string) bool { return self.view.HasMediator(mediatorName) } /* - Create and send an INotification. +SendNotification Create and send an INotification. - Keeps us from having to construct new notification - instances in our implementation code. +Keeps us from having to construct new notification +instances in our implementation code. - - parameter notificationName: the name of the notiification to send +- parameter notificationName: the name of the notiification to send - - parameter body: the body of the notification (optional) +- parameter body: the body of the notification (optional) - - parameter _type: the type of the notification +- parameter _type: the type of the notification */ func (self *Facade) SendNotification(notificationName string, body interface{}, _type string) { self.NotifyObservers(observer.NewNotification(notificationName, body, _type)) } /* - Notify Observers. +NotifyObservers Notify Observers. - This method is left mostly for backward - compatibility, and to allow you to send custom - notification classes using the facade. +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. +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. +- parameter notification: the INotification to have the View notify Observers of. */ func (self *Facade) NotifyObservers(notification interfaces.INotification) { self.view.NotifyObservers(notification) } /* - Set the Multiton key for this facade instance. +InitializeNotifier Set the Multiton key for this facade instance. - Not called directly, but instead from the - GetInstance when it is is invoked. +Not called directly, but instead from the +GetInstance when it is invoked. */ func (self *Facade) InitializeNotifier(key string) { self.Key = key } /* - Check if a Core is registered or not +HasCore Check if a Core is registered or not - - parameter key: the multiton key for the Core in question +- parameter key: the multiton key for the Core in question - - returns: whether a Core is registered with the given key. +- returns: whether a Core is registered with the given key. */ func HasCore(key string) bool { instanceMapMutex.RLock() @@ -305,12 +308,12 @@ func HasCore(key string) bool { } /* - Remove a Core. +RemoveCore Remove a Core. - Remove the Model, View, Controller and Facade - instances for the given key. +Remove the Model, View, Controller and Facade +instances for the given key. - - parameter key: multitonKey of the Core to remove +- parameter key: multitonKey of the Core to remove */ func RemoveCore(key string) { instanceMapMutex.Lock() diff --git a/src/patterns/facade/Notifier.go b/src/patterns/facade/Notifier.go index d686c15..26a3365 100755 --- a/src/patterns/facade/Notifier.go +++ b/src/patterns/facade/Notifier.go @@ -11,7 +11,7 @@ package facade import "github.com/puremvc/puremvc-go-multicore-framework/src/interfaces" /* -A Base INotifier implementation. +Notifier A Base INotifier implementation. MacroCommand, Command, Mediator and Proxy all have a need to send Notifications. @@ -22,7 +22,7 @@ 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 convienience method +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. @@ -45,37 +45,37 @@ type Notifier struct { } /* - Create and send an INotification. +SendNotification Create and send an INotification. - Keeps us from having to construct new INotification - instances in our implementation code. +Keeps us from having to construct new INotification +instances in our implementation code. - - parameter notificationName: the name of the notification to send +- parameter notificationName: the name of the notification to send - - parameter body: the body of the notification (optional) +- parameter body: the body of the notification (optional) - - parameter type: the _type of the notification +- parameter type: the _type of the notification */ func (self *Notifier) SendNotification(notificationName string, body interface{}, _type string) { self.Facade.SendNotification(notificationName, body, _type) } /* - Initialize this INotifier instance. +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. +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. +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 +- parameter key: the multitonKey for this INotifier to use */ func (self *Notifier) InitializeNotifier(key string) { self.Key = key diff --git a/src/patterns/mediator/Mediator.go b/src/patterns/mediator/Mediator.go index c0464a8..9d0a2de 100755 --- a/src/patterns/mediator/Mediator.go +++ b/src/patterns/mediator/Mediator.go @@ -16,7 +16,7 @@ import ( const NAME = "Mediator" // default name for the mediator /* -A base IMediator implementation. +Mediator A base IMediator implementation. */ type Mediator struct { facade.Notifier @@ -25,56 +25,56 @@ type Mediator struct { } /* - Get the name of the Mediator. +GetMediatorName Get the name of the Mediator. */ func (self *Mediator) GetMediatorName() string { return self.Name } /* - Get the IMediator's view component. +GetViewComponent Get the IMediator's view component. */ func (self *Mediator) GetViewComponent() interface{} { return self.ViewComponent } /* - Set the IMediator's view component. +SetViewComponent Set the IMediator's view component. */ func (self *Mediator) SetViewComponent(viewComponent interface{}) { self.ViewComponent = viewComponent } /* - List the INotification names this - Mediator is interested in being notified of. +ListNotificationInterests List the INotification names this +Mediator is interested in being notified of. - - returns: Array the list of INotification names +- returns: Array the list of INotification names */ func (self *Mediator) ListNotificationInterests() []string { return []string{} } /* - Handle INotifications. +HandleNotification Handle INotifications. - Typically this will be handled in a switch statement, - with one 'case' entry per INotification - the Mediator is interested in. +Typically, this will be handled in a switch statement, +with one 'case' entry per INotification +the Mediator is interested in. */ func (self *Mediator) HandleNotification(notification interfaces.INotification) { } /* - Called by the View when the Mediator is registered +OnRegister Called by the View when the Mediator is registered */ func (self *Mediator) OnRegister() { } /* - Called by the View when the Mediator is removed +OnRemove Called by the View when the Mediator is removed */ func (self *Mediator) OnRemove() { diff --git a/src/patterns/observer/Notification.go b/src/patterns/observer/Notification.go index f1051ae..b65b81c 100755 --- a/src/patterns/observer/Notification.go +++ b/src/patterns/observer/Notification.go @@ -9,7 +9,7 @@ package observer /* -A base INotification implementation. +Notification A base INotification implementation. PureMVC does not rely upon underlying event models such as the one provided with Flash, and ActionScript 3 does @@ -43,7 +43,7 @@ type Notification struct { } /* -Constructor. +NewNotification Constructor. - parameter name: name of the Notification instance. (required) @@ -56,44 +56,44 @@ func NewNotification(name string, body interface{}, _type string) *Notification } /* - Get the name of notification instance +Name Get the name of notification instance */ func (self *Notification) Name() string { return self.name } /* - Get the body of notification instance +Body Get the body of notification instance */ func (self *Notification) Body() interface{} { return self.body } /* - Set the body of notification instance +SetBody Set the body of notification instance */ func (self *Notification) SetBody(body interface{}) { self.body = body } /* - Get the type of notification instance +Type Get the type of notification instance */ func (self *Notification) Type() string { return self._type } /* - Set the type of notification instance +SetType Set the type of notification instance */ func (self *Notification) SetType(t string) { self._type = t } /* - Get the string representation of the Notification instance. +String Get the string representation of the Notification instance. - - returns: the string representation of the Notification instance. +- returns: the string representation of the Notification instance. */ func (self *Notification) String() string { msg := "Notification name: " + self.name diff --git a/src/patterns/observer/Observer.go b/src/patterns/observer/Observer.go index b65728e..6b4ecdf 100755 --- a/src/patterns/observer/Observer.go +++ b/src/patterns/observer/Observer.go @@ -11,7 +11,7 @@ package observer import "github.com/puremvc/puremvc-go-multicore-framework/src/interfaces" /* -A base IObserver implementation. +Observer A base IObserver implementation. An Observer is an object that encapsulates information about an interested object with a method that should @@ -33,34 +33,33 @@ type Observer struct { } /* - Notify the interested object. +NotifyObserver Notify the interested object. - - parameter notification: the INotification to pass to the interested object's notification method. +- parameter notification: the INotification to pass to the interested object's notification method. */ func (self *Observer) NotifyObserver(notification interfaces.INotification) { self.Notify(notification) } /* - Compare an object to the notification context. - - - parameter object: the object to compare - - returns: boolean indicating if the object and the notification context are the same +CompareNotifyContext Compare an object to the notification context. +- parameter object: the object to compare +- returns: boolean indicating if the object and the notification context are the same */ func (self *Observer) CompareNotifyContext(object interface{}) bool { return object == self.Context } /* - Set the notification method. +SetNotifyMethod Set the notification method. */ func (self *Observer) SetNotifyMethod(notifyMethod func(notification interfaces.INotification)) { self.Notify = notifyMethod } /* - Set the notification context. +SetNotifyContext Set the notification context. */ func (self *Observer) SetNotifyContext(notifyContext interface{}) { self.Context = notifyContext diff --git a/src/patterns/proxy/Proxy.go b/src/patterns/proxy/Proxy.go index 82ded5d..a9d604b 100755 --- a/src/patterns/proxy/Proxy.go +++ b/src/patterns/proxy/Proxy.go @@ -13,7 +13,7 @@ import "github.com/puremvc/puremvc-go-multicore-framework/src/patterns/facade" const NAME = "Proxy" // default name for the proxy /* -A base IProxy implementation. +Proxy A base IProxy implementation. In PureMVC, Proxy classes are used to manage parts of the application's data model. @@ -35,35 +35,35 @@ type Proxy struct { } /* - Get the proxy name +GetProxyName Get the proxy name */ func (self *Proxy) GetProxyName() string { return self.Name } /* - Set the data object +SetData Set the data object */ func (self *Proxy) SetData(data interface{}) { self.Data = data } /* - Get the data object +GetData Get the data object */ func (self *Proxy) GetData() interface{} { return self.Data } /* - Called by the Model when the Proxy is registered +OnRegister Called by the Model when the Proxy is registered */ func (self *Proxy) OnRegister() { } /* - Called by the Model when the Proxy is removed +OnRemove Called by the Model when the Proxy is removed */ func (self *Proxy) OnRemove() { diff --git a/test/core/controller/ControllerTestCommand.go b/test/core/controller/ControllerTestCommand.go index 57759c9..94cf0e6 100755 --- a/test/core/controller/ControllerTestCommand.go +++ b/test/core/controller/ControllerTestCommand.go @@ -14,18 +14,18 @@ import ( ) /* - A SimpleCommand subclass used by ControllerTest. +ControllerTestCommand A SimpleCommand subclass used by ControllerTest. */ type ControllerTestCommand struct { command.SimpleCommand } /* - Fabricate a result by multiplying the input by 2 +Execute Fabricate a result by multiplying the input by 2 - - parameter note: the note carrying the ControllerTestVO +- parameter note: the note carrying the ControllerTestVO */ -func (controller *ControllerTestCommand) Execute(notification interfaces.INotification) { +func (self *ControllerTestCommand) Execute(notification interfaces.INotification) { var vo = notification.Body().(*ControllerTestVO) // Fabricate a result diff --git a/test/core/controller/ControllerTestCommand2.go b/test/core/controller/ControllerTestCommand2.go index 31e3de2..c058561 100755 --- a/test/core/controller/ControllerTestCommand2.go +++ b/test/core/controller/ControllerTestCommand2.go @@ -14,20 +14,20 @@ import ( ) /* -A SimpleCommand subclass used by ControllerTest. +ControllerTestCommand2 A SimpleCommand subclass used by ControllerTest. */ type ControllerTestCommand2 struct { command.SimpleCommand } /* - Fabricate a result by multiplying the input by 2 and adding to the existing result +Execute Fabricate a result by multiplying the input by 2 and adding to the existing result - This tests accumulation effect that would show if the command were executed more than once. +This tests accumulation effect that would show if the command were executed more than once. - - parameter note: the note carrying the ControllerTestVO +- parameter note: the note carrying the ControllerTestVO */ -func (controller *ControllerTestCommand2) Execute(notification interfaces.INotification) { +func (self *ControllerTestCommand2) Execute(notification interfaces.INotification) { var vo = notification.Body().(*ControllerTestVO) // Fabricate a result diff --git a/test/core/controller/ControllerTestVO.go b/test/core/controller/ControllerTestVO.go index 3e892a0..035c5c2 100755 --- a/test/core/controller/ControllerTestVO.go +++ b/test/core/controller/ControllerTestVO.go @@ -9,7 +9,7 @@ package controller /* -A utility class used by ControllerTest. +ControllerTestVO A utility class used by ControllerTest. */ type ControllerTestVO struct { Input int diff --git a/test/core/controller/Controller_test.go b/test/core/controller/Controller_test.go index 9488cc8..a202599 100755 --- a/test/core/controller/Controller_test.go +++ b/test/core/controller/Controller_test.go @@ -21,33 +21,33 @@ Test the PureMVC Controller class. */ /* - Tests the Controller Multiton Factory Method +Tests the Controller Multiton Factory Method */ func TestGetInstance(t *testing.T) { - var controller = controller.GetInstance("ControllerTestKey1", func() interfaces.IController { return &controller.Controller{Key: "ControllerTestKey1"} }) + var c = controller.GetInstance("ControllerTestKey1", func() interfaces.IController { return &controller.Controller{Key: "ControllerTestKey1"} }) - if controller == nil { + if c == nil { t.Error("Expecting instance not nil") } } /* - Tests Command registration and execution. +Tests Command registration and execution. - This test gets a Multiton Controller instance - and registers the ControllerTestCommand class - to handle 'ControllerTest' Notifications. +This test gets a Multiton Controller instance +and registers the ControllerTestCommand class +to handle 'ControllerTest' Notifications. - It then constructs such a Notification and tells the - Controller to execute the associated Command. - Success is determined by evaluating a property - on an object passed to the Command, which will - be modified when the Command executes. +It then constructs such a Notification and tells the +Controller to execute the associated Command. +Success is determined by evaluating a property +on an object passed to the Command, which will +be modified when the Command executes. */ func TestRegisterAndExecuteCommand(t *testing.T) { // Create the controller, register the ControllerTestCommand to handle 'ControllerTest' notes - var controller = controller.GetInstance("ControllerTestKey2", func() interfaces.IController { return &controller.Controller{Key: "ControllerTestKey2"} }) - controller.RegisterCommand("ControllerTest", func() interfaces.ICommand { return &ControllerTestCommand{} }) + var c = controller.GetInstance("ControllerTestKey2", func() interfaces.IController { return &controller.Controller{Key: "ControllerTestKey2"} }) + c.RegisterCommand("ControllerTest", func() interfaces.ICommand { return &ControllerTestCommand{} }) // Create a 'ControllerTest' note var vo = ControllerTestVO{Input: 12} @@ -56,7 +56,7 @@ func TestRegisterAndExecuteCommand(t *testing.T) { // Tell the controller to execute the Command associated with the note // the ControllerTestCommand invoked will multiply the vo.input value // by 2 and set the result on vo.result - controller.ExecuteCommand(note) + c.ExecuteCommand(note) // test assertions if vo.Result != 24 { @@ -65,15 +65,15 @@ func TestRegisterAndExecuteCommand(t *testing.T) { } /* - Tests Command registration and removal. +Tests Command registration and removal. - Tests that once a Command is registered and verified - working, it can be removed from the Controller. +Tests that once a Command is registered and verified +working, it can be removed from the Controller. */ func TestRegisterAndRemoveCommand(t *testing.T) { // Create the controller, register the ControllerTestCommand to handle 'ControllerTest' notes - var controller = controller.GetInstance("ControllerTestKey3", func() interfaces.IController { return &controller.Controller{Key: "ControllerTestKey3"} }) - controller.RegisterCommand("ControllerRemoveTest", func() interfaces.ICommand { return &ControllerTestCommand{} }) + var c = controller.GetInstance("ControllerTestKey3", func() interfaces.IController { return &controller.Controller{Key: "ControllerTestKey3"} }) + c.RegisterCommand("ControllerRemoveTest", func() interfaces.ICommand { return &ControllerTestCommand{} }) // Create a 'ControllerTest' note var vo ControllerTestVO = ControllerTestVO{Input: 12} @@ -82,7 +82,7 @@ func TestRegisterAndRemoveCommand(t *testing.T) { // Tell the controller to execute the Command associated with the note // the ControllerTestCommand invoked will multiply the vo.input value // by 2 and set the result on vo.result - controller.ExecuteCommand(note) + c.ExecuteCommand(note) // test assertions if vo.Result != 24 { @@ -93,12 +93,12 @@ func TestRegisterAndRemoveCommand(t *testing.T) { vo.Result = 0 // Remove the Command from the Controller - controller.RemoveCommand("ControllerRemoveTest") + c.RemoveCommand("ControllerRemoveTest") // Tell the controller to execute the Command associated with the // note. This time, it should not be registered, and our vo result // will not change - controller.ExecuteCommand(note) + c.ExecuteCommand(note) // test assertions if vo.Result != 0 { @@ -107,56 +107,56 @@ func TestRegisterAndRemoveCommand(t *testing.T) { } /* - Test hasCommand method. +Test hasCommand method. */ func TestHasCommand(t *testing.T) { // register the ControllerTestCommand to handle 'hasCommandTest' notes - var controller = controller.GetInstance("ControllerTestKey4", func() interfaces.IController { return &controller.Controller{Key: "ControllerTestKey4"} }) - controller.RegisterCommand("hasCommandTest", func() interfaces.ICommand { return &ControllerTestCommand{} }) + var c = controller.GetInstance("ControllerTestKey4", func() interfaces.IController { return &controller.Controller{Key: "ControllerTestKey4"} }) + c.RegisterCommand("hasCommandTest", func() interfaces.ICommand { return &ControllerTestCommand{} }) // test that hasCommand returns true for hasCommandTest notifications - if controller.HasCommand("hasCommandTest") == false { + if c.HasCommand("hasCommandTest") == false { t.Error("Expecting controller.HasCommand('hasCommandTest') == true") } // Remove the Command from the Controller - controller.RemoveCommand("hasCommandTest") + c.RemoveCommand("hasCommandTest") // test that hasCommand returns false for hasCommandTest notifications - if controller.HasCommand("hasCommandTest") == true { + if c.HasCommand("hasCommandTest") == true { t.Error("Expecting controller.HasCommand('hasCommandTest') == false") } } /* - Tests Removing and Reregistering a Command +Tests Removing and Reregistering a Command - Tests that when a Command is re-registered that it isn't fired twice. - This involves, minimally, registration with the controller but - notification via the View, rather than direct execution of - the Controller's executeCommand method as is done above in - testRegisterAndRemove. +Tests that when a Command is re-registered that it isn't fired twice. +This involves, minimally, registration with the controller but +notification via the View, rather than direct execution of +the Controller's executeCommand method as is done above in +testRegisterAndRemove. */ func TestReregisterAndExecuteCommand(t *testing.T) { // Fetch the controller, register the ControllerTestCommand2 to handle 'ControllerTest2' notes - var controller = controller.GetInstance("ControllerTestKey5", func() interfaces.IController { return &controller.Controller{Key: "ControllerTestKey5"} }) - controller.RegisterCommand("ControllerTest2", func() interfaces.ICommand { return &ControllerTestCommand2{} }) + var c = controller.GetInstance("ControllerTestKey5", func() interfaces.IController { return &controller.Controller{Key: "ControllerTestKey5"} }) + c.RegisterCommand("ControllerTest2", func() interfaces.ICommand { return &ControllerTestCommand2{} }) // Remove the Command from the Controller - controller.RemoveCommand("ControllerTest2") + c.RemoveCommand("ControllerTest2") // Re-register the Command with the Controller - controller.RegisterCommand("ControllerTest2", func() interfaces.ICommand { return &ControllerTestCommand2{} }) + c.RegisterCommand("ControllerTest2", func() interfaces.ICommand { return &ControllerTestCommand2{} }) // Create a 'ControllerTest2' note var vo *ControllerTestVO = &ControllerTestVO{Input: 12} var note interfaces.INotification = observer.NewNotification("ControllerTest2", vo, "") // retrieve a reference to the View from the same core. - var view interfaces.IView = view.GetInstance("ControllerTestKey5", func() interfaces.IView { return &view.View{Key: "ControllerTestKey5"} }) + var v interfaces.IView = view.GetInstance("ControllerTestKey5", func() interfaces.IView { return &view.View{Key: "ControllerTestKey5"} }) // send the notification - view.NotifyObservers(note) + v.NotifyObservers(note) // test assertions // if the command is executed once the value will be 24 @@ -165,7 +165,7 @@ func TestReregisterAndExecuteCommand(t *testing.T) { } // Prove that accumulation works in the VO by sending the notification again - view.NotifyObservers(note) + v.NotifyObservers(note) // if the command is executed twice the value will be 48 if vo.Result != 48 { diff --git a/test/core/model/ModelTestProxy.go b/test/core/model/ModelTestProxy.go index 5134db0..8fbe868 100755 --- a/test/core/model/ModelTestProxy.go +++ b/test/core/model/ModelTestProxy.go @@ -18,10 +18,10 @@ type ModelTestProxy struct { proxy.Proxy } -func (proxy *ModelTestProxy) OnRegister() { - proxy.SetData(ON_REGISTER_CALLED) +func (self *ModelTestProxy) OnRegister() { + self.SetData(ON_REGISTER_CALLED) } -func (proxy *ModelTestProxy) OnRemove() { - proxy.SetData(ON_REMOVE_CALLED) +func (self *ModelTestProxy) OnRemove() { + self.SetData(ON_REMOVE_CALLED) } diff --git a/test/core/model/Model_test.go b/test/core/model/Model_test.go index 25f4bac..cf569b3 100755 --- a/test/core/model/Model_test.go +++ b/test/core/model/Model_test.go @@ -21,28 +21,28 @@ Test the PureMVC Model class. func TestGetInstance(t *testing.T) { // Test Factory Method - var model = model.GetInstance("ModelTestKey1", func() interfaces.IModel { return &model.Model{Key: "ModelTestKey1"} }) + var m = model.GetInstance("ModelTestKey1", func() interfaces.IModel { return &model.Model{Key: "ModelTestKey1"} }) // test assertions - if model == nil { + if m == nil { t.Error("Expecting instance not nil") } } /* - Tests the proxy registration and retrieval methods. +Tests the proxy registration and retrieval methods. - Tests registerProxy and retrieveProxy in the same test. - These methods cannot currently be tested separately - in any meaningful way other than to show that the - methods do not throw exception when called. +Tests registerProxy and retrieveProxy in the same test. +These methods cannot currently be tested separately +in any meaningful way other than to show that the +methods do not throw exception when called. */ func TestRegisterAndRetrieveProxy(t *testing.T) { // register a proxy and retrieve it. - var model = model.GetInstance("ModelTestKey2", func() interfaces.IModel { return &model.Model{Key: "ModelTestKey2"} }) - model.RegisterProxy(&proxy.Proxy{Name: "colors", Data: []string{"red", "green", "blue"}}) - var proxy = model.RetrieveProxy("colors") - var data = proxy.GetData().([]string) + var m = model.GetInstance("ModelTestKey2", func() interfaces.IModel { return &model.Model{Key: "ModelTestKey2"} }) + m.RegisterProxy(&proxy.Proxy{Name: "colors", Data: []string{"red", "green", "blue"}}) + var p = m.RetrieveProxy("colors") + var data = p.GetData().([]string) // test assertions if data == nil { @@ -63,16 +63,16 @@ func TestRegisterAndRetrieveProxy(t *testing.T) { } /* - Tests the proxy removal method. +Tests the proxy removal method. */ func TestRegisterAndRemoveProxy(t *testing.T) { // register a proxy, remove it, then try to retrieve it - var model = model.GetInstance("ModelTestKey3", func() interfaces.IModel { return &model.Model{Key: "ModelTestKey3"} }) - var proxy interfaces.IProxy = &proxy.Proxy{Name: "sizes", Data: []string{"7", "13", "21"}} - model.RegisterProxy(proxy) + var m = model.GetInstance("ModelTestKey3", func() interfaces.IModel { return &model.Model{Key: "ModelTestKey3"} }) + var p interfaces.IProxy = &proxy.Proxy{Name: "sizes", Data: []string{"7", "13", "21"}} + m.RegisterProxy(p) // remove the proxy - var removedProxy = model.RemoveProxy("sizes") + var removedProxy = m.RemoveProxy("sizes") // assert that we removed the appropriate proxy if removedProxy.GetProxyName() != "sizes" { @@ -80,7 +80,7 @@ func TestRegisterAndRemoveProxy(t *testing.T) { } // ensure that the proxy is no longer retrievable from the model - var nilProxy = model.RetrieveProxy("sizes") + var nilProxy = m.RetrieveProxy("sizes") // test assertions if nilProxy != nil { @@ -89,51 +89,51 @@ func TestRegisterAndRemoveProxy(t *testing.T) { } /* - Tests the hasProxy Method +Tests the hasProxy Method */ func TestHasProxy(t *testing.T) { // register a proxy - var model = model.GetInstance("ModelTestKey4", func() interfaces.IModel { return &model.Model{Key: "ModelTestKey4"} }) - var proxy interfaces.IProxy = &proxy.Proxy{Name: "aces", Data: []string{"clubs", "spades", "hearts", "diamonds"}} - model.RegisterProxy(proxy) + var m = model.GetInstance("ModelTestKey4", func() interfaces.IModel { return &model.Model{Key: "ModelTestKey4"} }) + var p interfaces.IProxy = &proxy.Proxy{Name: "aces", Data: []string{"clubs", "spades", "hearts", "diamonds"}} + m.RegisterProxy(p) // assert that the model.hasProxy method returns true // for that proxy name - if model.HasProxy("aces") != true { + if m.HasProxy("aces") != true { t.Error("Expecting model.HasProxy('aces') == true") } // remove the proxy - model.RemoveProxy("aces") + m.RemoveProxy("aces") // assert that the model.hasProxy method returns false // for that proxy name - if model.HasProxy("aces") != false { + if m.HasProxy("aces") != false { t.Error("Expecting model.HasProxy('aces') == false") } } /* - Tests that the Model calls the onRegister and onRemove methods +Tests that the Model calls the onRegister and onRemove methods */ func TestOnRegisterAndOnRemove(t *testing.T) { // Get a Multiton View instance - var model = model.GetInstance("ModelTestKey5", func() interfaces.IModel { return &model.Model{Key: "ModelTestKey5"} }) + var m = model.GetInstance("ModelTestKey5", func() interfaces.IModel { return &model.Model{Key: "ModelTestKey5"} }) // Create and register the test mediator - var proxy interfaces.IProxy = &ModelTestProxy{proxy.Proxy{Name: MODEL_TEST_PROXY}} - model.RegisterProxy(proxy) + var p interfaces.IProxy = &ModelTestProxy{proxy.Proxy{Name: MODEL_TEST_PROXY}} + m.RegisterProxy(p) // assert that onRegsiter was called, and the proxy responded by setting its data accordingly - if proxy.GetData() != ON_REGISTER_CALLED { + if p.GetData() != ON_REGISTER_CALLED { t.Error("Expecting proxy.GetData() == ON_REGISTER_CALLED") } // Remove the component - model.RemoveProxy(MODEL_TEST_PROXY) + m.RemoveProxy(MODEL_TEST_PROXY) // assert that onRemove was called, and the proxy responded by setting its data accordingly - if proxy.GetData() != ON_REMOVE_CALLED { + if p.GetData() != ON_REMOVE_CALLED { t.Error("Expecting proxy.GetData() == ON_REMOVE_CALLED") } } diff --git a/test/core/view/ViewTestMediator.go b/test/core/view/ViewTestMediator.go index 71b5699..bbea60b 100755 --- a/test/core/view/ViewTestMediator.go +++ b/test/core/view/ViewTestMediator.go @@ -13,13 +13,13 @@ import "github.com/puremvc/puremvc-go-multicore-framework/src/patterns/mediator" const ViewTestMediator_NAME = "ViewTestMediator" /* -A Mediator class used by ViewTest. +ViewTestMediator A Mediator class used by ViewTest. */ type ViewTestMediator struct { mediator.Mediator } -func (viewTestMediator *ViewTestMediator) ListNotificationInterests() []string { +func (self *ViewTestMediator) ListNotificationInterests() []string { // be sure that the mediator has some Observers created // in order to test removeMediator return []string{"ABC", "DEF", "GHI"} diff --git a/test/core/view/ViewTestMediator2.go b/test/core/view/ViewTestMediator2.go index ec3927d..8dda415 100755 --- a/test/core/view/ViewTestMediator2.go +++ b/test/core/view/ViewTestMediator2.go @@ -16,18 +16,18 @@ import ( const ViewTestMediator2_NAME = "viewTestMediator2" /* -A Mediator class used by ViewTest. +ViewTestMediator2 A Mediator class used by ViewTest. */ type ViewTestMediator2 struct { mediator.Mediator } -func (mediator *ViewTestMediator2) ListNotificationInterests() []string { +func (self *ViewTestMediator2) ListNotificationInterests() []string { // be sure that the mediator has some Observers created // in order to test removeMediator return []string{VIEWTEST_NOTE1, VIEWTEST_NOTE2} } -func (mediator *ViewTestMediator2) HandleNotification(notification interfaces.INotification) { - mediator.ViewComponent.(*Data).lastNotification = notification.Name() +func (self *ViewTestMediator2) HandleNotification(notification interfaces.INotification) { + self.ViewComponent.(*Data).lastNotification = notification.Name() } diff --git a/test/core/view/ViewTestMediator3.go b/test/core/view/ViewTestMediator3.go index d227482..e50c608 100755 --- a/test/core/view/ViewTestMediator3.go +++ b/test/core/view/ViewTestMediator3.go @@ -16,7 +16,7 @@ import ( const ViewTestMediator3_NAME = "viewTestMediator3" /* -A Mediator class used by ViewTest. +ViewTestMediator3 A Mediator class used by ViewTest. */ type ViewTestMediator3 struct { mediator.Mediator @@ -24,10 +24,10 @@ type ViewTestMediator3 struct { // be sure that the mediator has some Observers created // in order to test removeMediator -func (mediator *ViewTestMediator3) ListNotificationInterests() []string { +func (self *ViewTestMediator3) ListNotificationInterests() []string { return []string{VIEWTEST_NOTE3} } -func (mediator *ViewTestMediator3) HandleNotification(notification interfaces.INotification) { - mediator.ViewComponent.(*Data).lastNotification = notification.Name() +func (self *ViewTestMediator3) HandleNotification(notification interfaces.INotification) { + self.ViewComponent.(*Data).lastNotification = notification.Name() } diff --git a/test/core/view/ViewTestMediator4.go b/test/core/view/ViewTestMediator4.go index c3c8a9b..737dd15 100755 --- a/test/core/view/ViewTestMediator4.go +++ b/test/core/view/ViewTestMediator4.go @@ -13,16 +13,16 @@ import "github.com/puremvc/puremvc-go-multicore-framework/src/patterns/mediator" const ViewTestMediator4_NAME = "ViewTestMediator4" /* -A Mediator class used by ViewTest. +ViewTestMediator4 A Mediator class used by ViewTest. */ type ViewTestMediator4 struct { mediator.Mediator } -func (mediator *ViewTestMediator4) OnRegister() { - mediator.ViewComponent.(*Data).onRegisterCalled = true +func (self *ViewTestMediator4) OnRegister() { + self.ViewComponent.(*Data).onRegisterCalled = true } -func (mediator *ViewTestMediator4) OnRemove() { - mediator.ViewComponent.(*Data).onRemoveCalled = true +func (self *ViewTestMediator4) OnRemove() { + self.ViewComponent.(*Data).onRemoveCalled = true } diff --git a/test/core/view/ViewTestMediator5.go b/test/core/view/ViewTestMediator5.go index a6cec26..439225a 100755 --- a/test/core/view/ViewTestMediator5.go +++ b/test/core/view/ViewTestMediator5.go @@ -16,16 +16,16 @@ import ( const ViewTestMediator5_NAME = "viewTestMediator5" /* -A Mediator class used by ViewTest. +ViewTestMediator5 A Mediator class used by ViewTest. */ type ViewTestMediator5 struct { mediator.Mediator } -func (mediator *ViewTestMediator5) ListNotificationInterests() []string { +func (self *ViewTestMediator5) ListNotificationInterests() []string { return []string{VIEWTEST_NOTE5} } -func (mediator *ViewTestMediator5) HandleNotification(notification interfaces.INotification) { - mediator.ViewComponent.(*Data).counter++ +func (self *ViewTestMediator5) HandleNotification(notification interfaces.INotification) { + self.ViewComponent.(*Data).counter++ } diff --git a/test/core/view/ViewTestMediator6.go b/test/core/view/ViewTestMediator6.go index 94c31aa..bdf78c1 100755 --- a/test/core/view/ViewTestMediator6.go +++ b/test/core/view/ViewTestMediator6.go @@ -16,25 +16,25 @@ import ( const ViewTestMediator6_NAME = "ViewTestMediator6" // The Mediator base name /* -A Mediator class used by ViewTest. +ViewTestMediator6 A Mediator class used by ViewTest. */ type ViewTestMediator6 struct { mediator.Mediator } -func (mediator *ViewTestMediator6) ListNotificationInterests() []string { +func (self *ViewTestMediator6) ListNotificationInterests() []string { return []string{VIEWTEST_NOTE6} } -func (mediator *ViewTestMediator6) HandleNotification(notification interfaces.INotification) { +func (self *ViewTestMediator6) HandleNotification(notification interfaces.INotification) { //temp implementation until facade is developed - mediator.Notifier.Facade.RemoveMediator(mediator.GetMediatorName()) + self.Notifier.Facade.RemoveMediator(self.GetMediatorName()) //var view2 = view.GetInstance("ViewTestKey11", func() interfaces.IView { // return &view.View{Key: "ViewTestKey11"} //}) //view2.RemoveMediator(mediator.GetMediatorName()) } -func (mediator *ViewTestMediator6) OnRemove() { - mediator.ViewComponent.(*Data).counter++ +func (self *ViewTestMediator6) OnRemove() { + self.ViewComponent.(*Data).counter++ } diff --git a/test/core/view/ViewTestNote.go b/test/core/view/ViewTestNote.go index 53d0b12..e47e00b 100755 --- a/test/core/view/ViewTestNote.go +++ b/test/core/view/ViewTestNote.go @@ -21,21 +21,3 @@ type ViewTestNote struct { func ViewTestNoteNew(body interface{}) interfaces.INotification { return observer.NewNotification(ViewTestNote_NAME, body, "") } - -type ISuper interface{} - -type Super struct { - name string -} - -func NewSuper(name string) ISuper { - return &Super{name: name} -} - -type Sub struct { - Super -} - -func NewSub(name string) ISuper { - return Sub{Super{name}} -} diff --git a/test/core/view/View_test.go b/test/core/view/View_test.go index 2e4331b..5d23997 100755 --- a/test/core/view/View_test.go +++ b/test/core/view/View_test.go @@ -21,46 +21,46 @@ Test the PureMVC View class. */ /* - Tests the View Multiton Factory Method +Tests the View Multiton Factory Method */ func TestGetInstance(t *testing.T) { // Test Factory Method - var view = view.GetInstance("ViewTestKey1", func() interfaces.IView { return &view.View{Key: "ViewTestKey1"} }) + var v = view.GetInstance("ViewTestKey1", func() interfaces.IView { return &view.View{Key: "ViewTestKey1"} }) // test assertions - if view == nil { + if v == nil { t.Error("Expecting instance not nil") } } /* - Tests registration and notification of Observers. - - An Observer is created to callback the viewTestMethod of - this ViewTest instance. This Observer is registered with - the View to be notified of 'ViewTestEvent' events. Such - an event is created, and a value set on its payload. Then - the View is told to notify interested observers of this - Event. - - The View calls the Observer's notifyObserver method - which calls the viewTestMethod on this instance - of the ViewTest class. The viewTestMethod method will set - an instance variable to the value passed in on the Event - payload. We evaluate the instance variable to be sure - it is the same as that passed out as the payload of the - original 'ViewTestEvent'. +Tests registration and notification of Observers. + +An Observer is created to callback the viewTestMethod of +this ViewTest instance. This Observer is registered with +the View to be notified of 'ViewTestEvent' events. Such +an event is created, and a value set on its payload. Then +the View is told to notify interested observers of this +Event. + +The View calls the Observer's notifyObserver method +which calls the viewTestMethod on this instance +of the ViewTest class. The viewTestMethod method will set +an instance variable to the value passed in on the Event +payload. We evaluate the instance variable to be sure +it is the same as that passed out as the payload of the +original 'ViewTestEvent'. */ func TestRegisterAndNotifyObserver(t *testing.T) { // Get the Multiton View instance - var view = view.GetInstance("ViewTestKey2", func() interfaces.IView { return &view.View{Key: "ViewTestKey2"} }) + var v = view.GetInstance("ViewTestKey2", func() interfaces.IView { return &view.View{Key: "ViewTestKey2"} }) // Create observer, passing in notification method and context var observerTest = ObserverTest{NotifyMethod: NotifyTestMethod} var obs = &observer.Observer{Notify: observerTest.NotifyMethod, Context: observerTest} // Register Observer's interest in a particulat Notification with the View - view.RegisterObserver(ViewTestNote_NAME, obs) + v.RegisterObserver(ViewTestNote_NAME, obs) // Create a ViewTestNote, setting // a body value, and tell the View to notify @@ -70,7 +70,7 @@ func TestRegisterAndNotifyObserver(t *testing.T) { // viewTestVar being set to the value we pass in // on the note body. var note = ViewTestNoteNew(10) - view.NotifyObservers(note) + v.NotifyObservers(note) // test assertions if ViewTestVar != 10 { @@ -79,65 +79,65 @@ func TestRegisterAndNotifyObserver(t *testing.T) { } /* - Tests registering and retrieving a mediator with - the View. +Tests registering and retrieving a mediator with +the View. */ func TestRegisterAndRetrieveMediator(t *testing.T) { // Get the Multiton View instance - var view = view.GetInstance("ViewTestKey3", func() interfaces.IView { return &view.View{Key: "ViewTestKey3"} }) + var v = view.GetInstance("ViewTestKey3", func() interfaces.IView { return &view.View{Key: "ViewTestKey3"} }) // Create and register the test mediator var viewTestMediator interfaces.IMediator = &ViewTestMediator{Mediator: mediator.Mediator{Name: ViewTestMediator_NAME, ViewComponent: nil}} - view.RegisterMediator(viewTestMediator) + v.RegisterMediator(viewTestMediator) // Retrieve the component - var mediator = view.RetrieveMediator(ViewTestMediator_NAME) + var m = v.RetrieveMediator(ViewTestMediator_NAME) // test assertions - if mediator != viewTestMediator { + if m != viewTestMediator { t.Error("Expecting mediator is ViewTestMediator") } } /* - Tests the hasMediator Method +Tests the hasMediator Method */ func TestHasMediator(t *testing.T) { // register a Mediator - var view = view.GetInstance("ViewTestKey4", func() interfaces.IView { return &view.View{Key: "ViewTestKey4"} }) + var v = view.GetInstance("ViewTestKey4", func() interfaces.IView { return &view.View{Key: "ViewTestKey4"} }) // Create and register the test mediator - var mediator interfaces.IMediator = &mediator.Mediator{Name: "hasMediatorTest", ViewComponent: nil} - view.RegisterMediator(mediator) + var m interfaces.IMediator = &mediator.Mediator{Name: "hasMediatorTest", ViewComponent: nil} + v.RegisterMediator(m) // assert that the view.hasMediator method returns true // for that mediator name - if view.HasMediator("hasMediatorTest") != true { + if v.HasMediator("hasMediatorTest") != true { t.Error("Expecting view.HasMediator('hasMediatorTest')") } - view.RemoveMediator("hasMediatorTest") + v.RemoveMediator("hasMediatorTest") // assert that the view.hasMediator method returns false // for that mediator name - if view.HasMediator("hasMediatorTest") != false { + if v.HasMediator("hasMediatorTest") != false { t.Error("Expecting view.HasMediator('hasMediatorTest') == false") } } /* - Tests registering and removing a mediator +Tests registering and removing a mediator */ func TestRegisterAndRemoveMediator(t *testing.T) { // Get the Multiton View instance - var view = view.GetInstance("ViewTestKey5", func() interfaces.IView { return &view.View{Key: "ViewTestKey5"} }) + var v = view.GetInstance("ViewTestKey5", func() interfaces.IView { return &view.View{Key: "ViewTestKey5"} }) // Create and register the test mediator - var mediator interfaces.IMediator = &mediator.Mediator{Name: "testing", ViewComponent: nil} - view.RegisterMediator(mediator) + var m interfaces.IMediator = &mediator.Mediator{Name: "testing", ViewComponent: nil} + v.RegisterMediator(m) // Remove the component - var removedMediator = view.RemoveMediator("testing") + var removedMediator = v.RemoveMediator("testing") // assert that we have removed the appropriate mediator if removedMediator.GetMediatorName() != "testing" { @@ -145,22 +145,22 @@ func TestRegisterAndRemoveMediator(t *testing.T) { } // assert that the mediator is no longer retrievable - if view.RetrieveMediator("testing") != nil { + if v.RetrieveMediator("testing") != nil { t.Error("Expecting view.RetrieveMediator('testing') == nil") } } /* - Tests that the View callse the onRegister and onRemove methods +Tests that the View callse the onRegister and onRemove methods */ func TestOnRegisterAndOnRemove(t *testing.T) { // Get the Multiton View instance - var view = view.GetInstance("ViewTestKey6", func() interfaces.IView { return &view.View{Key: "ViewTestKey6"} }) + var v = view.GetInstance("ViewTestKey6", func() interfaces.IView { return &view.View{Key: "ViewTestKey6"} }) // Create and register the test mediator var data = Data{} - var mediator interfaces.IMediator = &ViewTestMediator4{mediator.Mediator{Name: ViewTestMediator4_NAME, ViewComponent: &data}} - view.RegisterMediator(mediator) + var m interfaces.IMediator = &ViewTestMediator4{mediator.Mediator{Name: ViewTestMediator4_NAME, ViewComponent: &data}} + v.RegisterMediator(m) // assert that onRegsiter was called, and the mediator responded by setting our boolean if data.onRegisterCalled != true { @@ -168,7 +168,7 @@ func TestOnRegisterAndOnRemove(t *testing.T) { } // Remove the component - view.RemoveMediator(ViewTestMediator4_NAME) + v.RemoveMediator(ViewTestMediator4_NAME) // assert that the mediator is no longer retrievable if data.onRemoveCalled != true { @@ -177,80 +177,80 @@ func TestOnRegisterAndOnRemove(t *testing.T) { } /* - Tests successive regster and remove of same mediator. +Tests successive register and remove of same mediator. */ func TestSuccessiveRegisterAndRemoveMediator(t *testing.T) { // Get the Multiton View instance - var view = view.GetInstance("ViewTestKey7", func() interfaces.IView { return &view.View{Key: "ViewTestKey7"} }) - var _mediator = &ViewTestMediator{Mediator: mediator.Mediator{Name: ViewTestMediator_NAME, ViewComponent: nil}} + var v = view.GetInstance("ViewTestKey7", func() interfaces.IView { return &view.View{Key: "ViewTestKey7"} }) + var m = &ViewTestMediator{Mediator: mediator.Mediator{Name: ViewTestMediator_NAME, ViewComponent: nil}} // Create and register the test mediator, // but not so we have a reference to it - view.RegisterMediator(_mediator) + v.RegisterMediator(m) // test that we can retrieve it - if view.RetrieveMediator(ViewTestMediator_NAME) != _mediator { + if v.RetrieveMediator(ViewTestMediator_NAME) != m { t.Error("Expecting view.RetrieveMediator(ViewTestMediatorNAME) == mediator") } // Remove the Mediator - view.RemoveMediator(ViewTestMediator_NAME) + v.RemoveMediator(ViewTestMediator_NAME) // test that retrieving it now returns nil - if view.RetrieveMediator(ViewTestMediator_NAME) != nil { + if v.RetrieveMediator(ViewTestMediator_NAME) != nil { t.Error("Expecting view.RetrieveMediator(ViewTestMediator.NAME) == nil") } // test that removing the mediator again once its gone doesn't cause crash - if view.RetrieveMediator(ViewTestMediator_NAME) != nil { + if v.RetrieveMediator(ViewTestMediator_NAME) != nil { t.Error("Expecting view.RetrieveMediator(ViewTestMediator.NAME) == nil") } // Create and register another instance of the test mediator, - view.RegisterMediator(&ViewTestMediator{Mediator: mediator.Mediator{Name: ViewTestMediator_NAME, ViewComponent: nil}}) + v.RegisterMediator(&ViewTestMediator{Mediator: mediator.Mediator{Name: ViewTestMediator_NAME, ViewComponent: nil}}) - if view.RetrieveMediator(ViewTestMediator_NAME) == nil { + if v.RetrieveMediator(ViewTestMediator_NAME) == nil { t.Error("Expecting view.RetrieveMediator(ViewTestMediator_NAME) != nil") } // Remove the Mediator - view.RemoveMediator(ViewTestMediator_NAME) + v.RemoveMediator(ViewTestMediator_NAME) // test that retrieving it now returns nil - if view.RetrieveMediator(ViewTestMediator_NAME) != nil { + if v.RetrieveMediator(ViewTestMediator_NAME) != nil { t.Error("Expecting view.RetrieveMediator(ViewTestMediator_NAME) == nil") } } /* - Tests registering a Mediator for 2 different notifications, removing the - Mediator from the View, and seeing that neither notification causes the - Mediator to be notified. +Tests registering a Mediator for 2 different notifications, removing the +Mediator from the View, and seeing that neither notification causes the +Mediator to be notified. */ func TestRemoveMediatorAndSubsequentNotify(t *testing.T) { // Get the Multiton View instance - var view = view.GetInstance("ViewTestKey8", func() interfaces.IView { return &view.View{Key: "ViewTestKey8"} }) + var v = view.GetInstance("ViewTestKey8", func() interfaces.IView { return &view.View{Key: "ViewTestKey8"} }) // Create and register the test mediator to be removed. var data = Data{} - view.RegisterMediator(&ViewTestMediator2{Mediator: mediator.Mediator{Name: ViewTestMediator2_NAME, ViewComponent: &data}}) + v.RegisterMediator(&ViewTestMediator2{Mediator: mediator.Mediator{Name: ViewTestMediator2_NAME, ViewComponent: &data}}) // test that notifications work - view.NotifyObservers(observer.NewNotification(VIEWTEST_NOTE1, "", "")) + v.NotifyObservers(observer.NewNotification(VIEWTEST_NOTE1, "", "")) if data.lastNotification != VIEWTEST_NOTE1 { t.Error("Expecting data.lastNotification == VIEWTEST_NOTE1") } - view.NotifyObservers(observer.NewNotification(VIEWTEST_NOTE2, "", "")) + v.NotifyObservers(observer.NewNotification(VIEWTEST_NOTE2, "", "")) if data.lastNotification != VIEWTEST_NOTE2 { t.Error("Expecting data.lastNotification == VIEWTEST_NOTE2") } // Remove the Mediator - view.RemoveMediator(ViewTestMediator2_NAME) + v.RemoveMediator(ViewTestMediator2_NAME) // test that retrieving it now returns nil - if view.RetrieveMediator(ViewTestMediator2_NAME) != nil { + if v.RetrieveMediator(ViewTestMediator2_NAME) != nil { t.Error("Expecting view.RetrieveMediator(ViewTestMediator2.NAME) == nil") } @@ -259,53 +259,53 @@ func TestRemoveMediatorAndSubsequentNotify(t *testing.T) { // on this component, and ViewTestMediator) data.lastNotification = "" - view.NotifyObservers(observer.NewNotification(VIEWTEST_NOTE1, "", "")) + v.NotifyObservers(observer.NewNotification(VIEWTEST_NOTE1, "", "")) if data.lastNotification != "" { t.Error("Expecting data.lastNotification == ''") } - view.NotifyObservers(observer.NewNotification(VIEWTEST_NOTE2, "", "")) + v.NotifyObservers(observer.NewNotification(VIEWTEST_NOTE2, "", "")) if data.lastNotification != "" { t.Error("Expecting data.lastNotification == ''") } } /* - Tests registering one of two registered Mediators and seeing - that the remaining one still responds. +Tests registering one of two registered Mediators and seeing +that the remaining one still responds. */ func TestRemoveOneOfTwoMediatorsAndSubsequentNotify(t *testing.T) { // Get the Multiton View instance - var view = view.GetInstance("ViewTestKey9", func() interfaces.IView { return &view.View{Key: "ViewTestKey9"} }) + var v = view.GetInstance("ViewTestKey9", func() interfaces.IView { return &view.View{Key: "ViewTestKey9"} }) // Create and register that responds to notifications 1 and 2 var data = Data{} - view.RegisterMediator(&ViewTestMediator2{Mediator: mediator.Mediator{Name: ViewTestMediator2_NAME, ViewComponent: &data}}) + v.RegisterMediator(&ViewTestMediator2{Mediator: mediator.Mediator{Name: ViewTestMediator2_NAME, ViewComponent: &data}}) // Create and register that responds to notification 3 - view.RegisterMediator(&ViewTestMediator3{Mediator: mediator.Mediator{Name: ViewTestMediator3_NAME, ViewComponent: &data}}) + v.RegisterMediator(&ViewTestMediator3{Mediator: mediator.Mediator{Name: ViewTestMediator3_NAME, ViewComponent: &data}}) // test that all notifications work - view.NotifyObservers(observer.NewNotification(VIEWTEST_NOTE1, "", "")) + v.NotifyObservers(observer.NewNotification(VIEWTEST_NOTE1, "", "")) if data.lastNotification != VIEWTEST_NOTE1 { t.Error("Expecting data.lastNotification == VIEWTEST_NOTE1") } - view.NotifyObservers(observer.NewNotification(VIEWTEST_NOTE2, "", "")) + v.NotifyObservers(observer.NewNotification(VIEWTEST_NOTE2, "", "")) if data.lastNotification != VIEWTEST_NOTE2 { t.Error("Expecting data.lastNotification == VIEWTEST_NOTE2") } - view.NotifyObservers(observer.NewNotification(VIEWTEST_NOTE3, "", "")) + v.NotifyObservers(observer.NewNotification(VIEWTEST_NOTE3, "", "")) if data.lastNotification != VIEWTEST_NOTE3 { t.Error("Expecting data.lastNotification == VIEWTEST_NOTE3") } // Remove the Mediator that responds to 1 and 2 - view.RemoveMediator(ViewTestMediator2_NAME) + v.RemoveMediator(ViewTestMediator2_NAME) // test that retrieving it now returns nil - if view.RetrieveMediator(ViewTestMediator2_NAME) != nil { + if v.RetrieveMediator(ViewTestMediator2_NAME) != nil { t.Error("Expecting view.RetrieveMediator(ViewTestMediator2_NAME) == nil") } @@ -313,94 +313,93 @@ func TestRemoveOneOfTwoMediatorsAndSubsequentNotify(t *testing.T) { // for notifications 1 and 2, but still work for 3 data.lastNotification = "" - view.NotifyObservers(observer.NewNotification(VIEWTEST_NOTE1, "", "")) + v.NotifyObservers(observer.NewNotification(VIEWTEST_NOTE1, "", "")) if data.lastNotification == VIEWTEST_NOTE1 { t.Error("Expecting data.lastNotification != VIEWTEST_NOTE1") } - view.NotifyObservers(observer.NewNotification(VIEWTEST_NOTE2, "", "")) + v.NotifyObservers(observer.NewNotification(VIEWTEST_NOTE2, "", "")) if data.lastNotification == VIEWTEST_NOTE2 { t.Error("Expecting data.lastNotification != VIEWTEST_NOTE2") } - view.NotifyObservers(observer.NewNotification(VIEWTEST_NOTE3, "", "")) + v.NotifyObservers(observer.NewNotification(VIEWTEST_NOTE3, "", "")) if data.lastNotification != VIEWTEST_NOTE3 { t.Error("Expecting data.lastNotification == VIEWTEST_NOTE3") } } /* - Tests registering the same mediator twice. - A subsequent notification should only illicit - one response. Also, since reregistration - was causing 2 observers to be created, ensure - that after removal of the mediator there will - be no further response. +Tests registering the same mediator twice. +A subsequent notification should only illicit +one response. Also, since reregistration +was causing 2 observers to be created, ensure +that after removal of the mediator there will +be no further response. */ func TestMediatorReregistration(t *testing.T) { // Get the Multiton View instance - var view = view.GetInstance("ViewTestKey10", func() interfaces.IView { return &view.View{Key: "ViewTestKey10"} }) + var v = view.GetInstance("ViewTestKey10", func() interfaces.IView { return &view.View{Key: "ViewTestKey10"} }) // Create and register that responds to notification 5 var data = Data{} - view.RegisterMediator(&ViewTestMediator5{Mediator: mediator.Mediator{Name: ViewTestMediator5_NAME, ViewComponent: &data}}) + v.RegisterMediator(&ViewTestMediator5{Mediator: mediator.Mediator{Name: ViewTestMediator5_NAME, ViewComponent: &data}}) // try to register another instance of that mediator (uses the same NAME constant). - view.RegisterMediator(&ViewTestMediator5{Mediator: mediator.Mediator{Name: ViewTestMediator5_NAME, ViewComponent: &data}}) + v.RegisterMediator(&ViewTestMediator5{Mediator: mediator.Mediator{Name: ViewTestMediator5_NAME, ViewComponent: &data}}) // test that the counter is only incremented once (mediator 5's response) - view.NotifyObservers(observer.NewNotification(VIEWTEST_NOTE5, "", "")) + v.NotifyObservers(observer.NewNotification(VIEWTEST_NOTE5, "", "")) if data.counter != 1 { t.Error("Expecting counter == 1") } // Remove the Mediator - view.RemoveMediator(ViewTestMediator5_NAME) + v.RemoveMediator(ViewTestMediator5_NAME) // test that retrieving it now returns nil - if view.RetrieveMediator(ViewTestMediator5_NAME) != nil { + if v.RetrieveMediator(ViewTestMediator5_NAME) != nil { t.Error("Expecting view.RetrieveMediator(ViewTestMediator5_NAME) == nil") } // test that the counter is no longer incremented data.counter = 0 - view.NotifyObservers(observer.NewNotification(VIEWTEST_NOTE5, "", "")) + v.NotifyObservers(observer.NewNotification(VIEWTEST_NOTE5, "", "")) if data.counter != 0 { t.Error("Expecting counter == 0") } } /* - - Tests the ability for the observer list to - be modified during the process of notification, - and all observers be properly notified. This - happens most often when multiple Mediators - respond to the same notification by removing - themselves. +Tests the ability for the observer list to +be modified during the process of notification, +and all observers be properly notified. This +happens most often when multiple Mediators +respond to the same notification by removing +themselves. */ func TestModifyObserverListDuringNotification(t *testing.T) { // Get the Multiton View instance - var view = view.GetInstance("ViewTestKey11", func() interfaces.IView { return &view.View{Key: "ViewTestKey11"} }) + var v = view.GetInstance("ViewTestKey11", func() interfaces.IView { return &view.View{Key: "ViewTestKey11"} }) // Create and register several mediator instances that respond to notification 6 // by removing themselves, which will cause the observer list for that notification // to change. versions prior to MultiCore Version 2.0.5 will see every other mediator // fails to be notified. var data = Data{} - view.RegisterMediator(&ViewTestMediator6{Mediator: mediator.Mediator{Name: ViewTestMediator6_NAME + "/1", ViewComponent: &data}}) - view.RegisterMediator(&ViewTestMediator6{Mediator: mediator.Mediator{Name: ViewTestMediator6_NAME + "/2", ViewComponent: &data}}) - view.RegisterMediator(&ViewTestMediator6{Mediator: mediator.Mediator{Name: ViewTestMediator6_NAME + "/3", ViewComponent: &data}}) - view.RegisterMediator(&ViewTestMediator6{Mediator: mediator.Mediator{Name: ViewTestMediator6_NAME + "/4", ViewComponent: &data}}) - view.RegisterMediator(&ViewTestMediator6{Mediator: mediator.Mediator{Name: ViewTestMediator6_NAME + "/5", ViewComponent: &data}}) - view.RegisterMediator(&ViewTestMediator6{Mediator: mediator.Mediator{Name: ViewTestMediator6_NAME + "/6", ViewComponent: &data}}) - view.RegisterMediator(&ViewTestMediator6{Mediator: mediator.Mediator{Name: ViewTestMediator6_NAME + "/7", ViewComponent: &data}}) - view.RegisterMediator(&ViewTestMediator6{Mediator: mediator.Mediator{Name: ViewTestMediator6_NAME + "/8", ViewComponent: &data}}) + v.RegisterMediator(&ViewTestMediator6{Mediator: mediator.Mediator{Name: ViewTestMediator6_NAME + "/1", ViewComponent: &data}}) + v.RegisterMediator(&ViewTestMediator6{Mediator: mediator.Mediator{Name: ViewTestMediator6_NAME + "/2", ViewComponent: &data}}) + v.RegisterMediator(&ViewTestMediator6{Mediator: mediator.Mediator{Name: ViewTestMediator6_NAME + "/3", ViewComponent: &data}}) + v.RegisterMediator(&ViewTestMediator6{Mediator: mediator.Mediator{Name: ViewTestMediator6_NAME + "/4", ViewComponent: &data}}) + v.RegisterMediator(&ViewTestMediator6{Mediator: mediator.Mediator{Name: ViewTestMediator6_NAME + "/5", ViewComponent: &data}}) + v.RegisterMediator(&ViewTestMediator6{Mediator: mediator.Mediator{Name: ViewTestMediator6_NAME + "/6", ViewComponent: &data}}) + v.RegisterMediator(&ViewTestMediator6{Mediator: mediator.Mediator{Name: ViewTestMediator6_NAME + "/7", ViewComponent: &data}}) + v.RegisterMediator(&ViewTestMediator6{Mediator: mediator.Mediator{Name: ViewTestMediator6_NAME + "/8", ViewComponent: &data}}) // send the notification. each of the above mediators will respond by removing // themselves and incrementing the counter by 1. This should leave us with a // count of 8, since 8 mediators will respond. - view.NotifyObservers(observer.NewNotification(VIEWTEST_NOTE6, "", "")) + v.NotifyObservers(observer.NewNotification(VIEWTEST_NOTE6, "", "")) // verify the count is correct if data.counter != 8 { @@ -409,7 +408,7 @@ func TestModifyObserverListDuringNotification(t *testing.T) { // clear the counter data.counter = 0 - view.NotifyObservers(observer.NewNotification(VIEWTEST_NOTE6, "", "")) + v.NotifyObservers(observer.NewNotification(VIEWTEST_NOTE6, "", "")) // verify the count is 0 if data.counter != 0 { diff --git a/test/patterns/command/MacroCommandTestCommand.go b/test/patterns/command/MacroCommandTestCommand.go index 3d068a9..a908fcc 100755 --- a/test/patterns/command/MacroCommandTestCommand.go +++ b/test/patterns/command/MacroCommandTestCommand.go @@ -14,22 +14,22 @@ import ( ) /* -A MacroCommand subclass used by MacroCommandTest. +MacroCommandTestCommand A MacroCommand subclass used by MacroCommandTest. */ type MacroCommandTestCommand struct { command.MacroCommand } /* - Initialize the MacroCommandTestCommand by adding - its 2 SubCommands. +InitializeMacroCommand Initialize the MacroCommandTestCommand by adding +its 2 SubCommands. */ -func (command *MacroCommandTestCommand) InitializeMacroCommand() { - command.AddSubCommand(func() interfaces.ICommand { return &MacroCommandTestSub1Command{} }) - command.AddSubCommand(func() interfaces.ICommand { return &MacroCommandTestSub2Command{} }) +func (self *MacroCommandTestCommand) InitializeMacroCommand() { + self.AddSubCommand(func() interfaces.ICommand { return &MacroCommandTestSub1Command{} }) + self.AddSubCommand(func() interfaces.ICommand { return &MacroCommandTestSub2Command{} }) } -func (command *MacroCommandTestCommand) Execute(notification interfaces.INotification) { - command.InitializeMacroCommand() // AddSubCommands - command.MacroCommand.Execute(notification) // Execute SubCommands +func (self *MacroCommandTestCommand) Execute(notification interfaces.INotification) { + self.InitializeMacroCommand() // AddSubCommands + self.MacroCommand.Execute(notification) // Execute SubCommands } diff --git a/test/patterns/command/MacroCommandTestSub1Command.go b/test/patterns/command/MacroCommandTestSub1Command.go index 45f4722..4c00d51 100755 --- a/test/patterns/command/MacroCommandTestSub1Command.go +++ b/test/patterns/command/MacroCommandTestSub1Command.go @@ -18,11 +18,11 @@ type MacroCommandTestSub1Command struct { } /* - Fabricate a result by multiplying the input by 2 +Execute Fabricate a result by multiplying the input by 2 - - parameter event: the IEvent carrying the MacroCommandTestVO +- parameter event: the IEvent carrying the MacroCommandTestVO */ -func (command *MacroCommandTestSub1Command) Execute(notification interfaces.INotification) { +func (self *MacroCommandTestSub1Command) Execute(notification interfaces.INotification) { var vo = notification.Body().(*MacroCommandTestVO) // Fabricate a result diff --git a/test/patterns/command/MacroCommandTestSub2Command.go b/test/patterns/command/MacroCommandTestSub2Command.go index b9ca773..c759283 100755 --- a/test/patterns/command/MacroCommandTestSub2Command.go +++ b/test/patterns/command/MacroCommandTestSub2Command.go @@ -18,11 +18,11 @@ type MacroCommandTestSub2Command struct { } /* - Fabricate a result by multiplying the input by itself +Execute Fabricate a result by multiplying the input by itself - - parameter event: the IEvent carrying the MacroCommandTestVO +- parameter event: the IEvent carrying the MacroCommandTestVO */ -func (command *MacroCommandTestSub2Command) Execute(notification interfaces.INotification) { +func (self *MacroCommandTestSub2Command) Execute(notification interfaces.INotification) { var vo = notification.Body().(*MacroCommandTestVO) // Fabricate a result diff --git a/test/patterns/command/MacroCommandTestVO.go b/test/patterns/command/MacroCommandTestVO.go index edb7d80..78837b9 100755 --- a/test/patterns/command/MacroCommandTestVO.go +++ b/test/patterns/command/MacroCommandTestVO.go @@ -9,7 +9,7 @@ package command /* -A utility class used by MacroCommandTest. +MacroCommandTestVO A utility class used by MacroCommandTest. */ type MacroCommandTestVO struct { Input int diff --git a/test/patterns/command/MacroCommand_test.go b/test/patterns/command/MacroCommand_test.go index ced3f95..b2acf2e 100755 --- a/test/patterns/command/MacroCommand_test.go +++ b/test/patterns/command/MacroCommand_test.go @@ -52,11 +52,11 @@ func TestMacroCommandExecute(t *testing.T) { var note = observer.NewNotification("MacroCommandTest", &vo, "") // Create the SimpleCommand - var command = MacroCommandTestCommand{MacroCommand: command.MacroCommand{}} - command.Notifier.InitializeNotifier("test") + var mc = MacroCommandTestCommand{MacroCommand: command.MacroCommand{}} + mc.Notifier.InitializeNotifier("test") // Execute the SimpleCommand - command.Execute(note) + mc.Execute(note) // test assertions if vo.Result1 != 10 { @@ -68,17 +68,17 @@ func TestMacroCommandExecute(t *testing.T) { } /* - Testing MacroCommand via Controller and notify via View +Testing MacroCommand via Controller and notify via View */ func TestMacroCommandExecuteViaControllerView(t *testing.T) { - var controller = controller.GetInstance("MacroCommandTest2", func() interfaces.IController { return &controller.Controller{Key: "MacroCommandTest2"} }) - var view = view.GetInstance("MacroCommandTest2", func() interfaces.IView { return &view.View{Key: "MacroCommandTest2"} }) + var c = controller.GetInstance("MacroCommandTest2", func() interfaces.IController { return &controller.Controller{Key: "MacroCommandTest2"} }) + var v = view.GetInstance("MacroCommandTest2", func() interfaces.IView { return &view.View{Key: "MacroCommandTest2"} }) - controller.RegisterCommand("MacroCommandTestViaControllerView", func() interfaces.ICommand { return &MacroCommandTestCommand{} }) + c.RegisterCommand("MacroCommandTestViaControllerView", func() interfaces.ICommand { return &MacroCommandTestCommand{} }) var vo = MacroCommandTestVO{Input: 5} var note = observer.NewNotification("MacroCommandTestViaControllerView", &vo, "") - view.NotifyObservers(note) + v.NotifyObservers(note) if vo.Result1 != 10 { t.Error("Expecting vo.Result1 == 10") diff --git a/test/patterns/command/SimpleCommandTestCommand.go b/test/patterns/command/SimpleCommandTestCommand.go index 44ecacc..0ae1c6e 100755 --- a/test/patterns/command/SimpleCommandTestCommand.go +++ b/test/patterns/command/SimpleCommandTestCommand.go @@ -11,17 +11,17 @@ package command import "github.com/puremvc/puremvc-go-multicore-framework/src/interfaces" /* -A SimpleCommand subclass used by SimpleCommandTest. +SimpleCommandTestCommand A SimpleCommand subclass used by SimpleCommandTest. */ type SimpleCommandTestCommand struct { } /* - Fabricate a result by multiplying the input by 2 +Execute Fabricate a result by multiplying the input by 2 - - parameter event: the INotification carrying the SimpleCommandTestVO +- parameter event: the INotification carrying the SimpleCommandTestVO */ -func (command SimpleCommandTestCommand) execute(notification interfaces.INotification) { +func (self *SimpleCommandTestCommand) Execute(notification interfaces.INotification) { var vo = notification.Body().(*SimpleCommandTestVO) //Fabricate a result diff --git a/test/patterns/command/SimpleCommandTestVO.go b/test/patterns/command/SimpleCommandTestVO.go index efeb6d1..73e5476 100755 --- a/test/patterns/command/SimpleCommandTestVO.go +++ b/test/patterns/command/SimpleCommandTestVO.go @@ -9,7 +9,7 @@ package command /* -A utility class used by SimpleCommandTest. +SimpleCommandTestVO A utility class used by SimpleCommandTest. */ type SimpleCommandTestVO struct { Input int diff --git a/test/patterns/command/SimpleCommand_test.go b/test/patterns/command/SimpleCommand_test.go index 735bd3d..3a581b6 100755 --- a/test/patterns/command/SimpleCommand_test.go +++ b/test/patterns/command/SimpleCommand_test.go @@ -18,16 +18,16 @@ import ( */ /* - Tests the execute method of a SimpleCommand. +Tests the execute method of a SimpleCommand. - This test creates a new Notification, adding a - SimpleCommandTestVO as the body. - It then creates a SimpleCommandTestCommand and invokes - its execute method, passing in the note. +This test creates a new Notification, adding a +SimpleCommandTestVO as the body. +It then creates a SimpleCommandTestCommand and invokes +its execute method, passing in the note. - Success is determined by evaluating a property on the - object that was passed on the Notification body, which will - be modified by the SimpleCommand. +Success is determined by evaluating a property on the +object that was passed on the Notification body, which will +be modified by the SimpleCommand. */ func TestSimpleCommandExecute(t *testing.T) { // Create the VO @@ -40,7 +40,7 @@ func TestSimpleCommandExecute(t *testing.T) { var command = SimpleCommandTestCommand{} // Execute the SimpleCommand - command.execute(note) + command.Execute(note) // test assertions if vo.Result != 10 { diff --git a/test/patterns/facade/FacadeTestCommand.go b/test/patterns/facade/FacadeTestCommand.go index 32fb125..0fb1aea 100755 --- a/test/patterns/facade/FacadeTestCommand.go +++ b/test/patterns/facade/FacadeTestCommand.go @@ -14,18 +14,18 @@ import ( ) /* -A SimpleCommand subclass used by FacadeTest. +FacadeTestCommand A SimpleCommand subclass used by FacadeTest. */ type FacadeTestCommand struct { command.SimpleCommand } /* - Fabricate a result by multiplying the input by 2 +Execute Fabricate a result by multiplying the input by 2 - - parameter note: the Notification carrying the FacadeTestVO +- parameter note: the Notification carrying the FacadeTestVO */ -func (facade *FacadeTestCommand) Execute(notification interfaces.INotification) { +func (self *FacadeTestCommand) Execute(notification interfaces.INotification) { var vo = notification.Body().(*FacadeTestVO) // Fabricate a Result diff --git a/test/patterns/facade/FacadeTestVO.go b/test/patterns/facade/FacadeTestVO.go index a41f6f4..1fbf5c6 100755 --- a/test/patterns/facade/FacadeTestVO.go +++ b/test/patterns/facade/FacadeTestVO.go @@ -9,7 +9,7 @@ package facade /* -A utility class used by FacadeTest. +FacadeTestVO A utility class used by FacadeTest. */ type FacadeTestVO struct { Input int diff --git a/test/patterns/facade/Facade_test.go b/test/patterns/facade/Facade_test.go index 08d8d81..28c31cc 100755 --- a/test/patterns/facade/Facade_test.go +++ b/test/patterns/facade/Facade_test.go @@ -22,37 +22,37 @@ Test the PureMVC Facade class. func TestGetInstance(t *testing.T) { // Test Factory Method - var facade = facade.GetInstance("FacadeTestKey1", func() interfaces.IFacade { return &facade.Facade{Key: "FacadeTestKey1"} }) + var f = facade.GetInstance("FacadeTestKey1", func() interfaces.IFacade { return &facade.Facade{Key: "FacadeTestKey1"} }) // test assertions - if facade == nil { + if f == nil { t.Error("Expecting instance not nil") } } /* - Tests Command registration and execution via the Facade. +Tests Command registration and execution via the Facade. - This test gets a Multiton Facade instance - and registers the FacadeTestCommand class - to handle 'FacadeTest' Notifcations. +This test gets a Multiton Facade instance +and registers the FacadeTestCommand class +to handle 'FacadeTest' Notifications. - It then sends a notification using the Facade. - Success is determined by evaluating - a property on an object placed in the body of - the Notification, which will be modified by the Command. +It then sends a notification using the Facade. +Success is determined by evaluating +a property on an object placed in the body of +the Notification, which will be modified by the Command. */ func TestRegisterCommandAndSendNotification(t *testing.T) { // Create the Facade, register the FacadeTestCommand to // handle 'FacadeTest' notifications - var facade = facade.GetInstance("FacadeTestKey2", func() interfaces.IFacade { return &facade.Facade{Key: "FacadeTestKey2"} }) - facade.RegisterCommand("FacadeTestNote", func() interfaces.ICommand { return &FacadeTestCommand{} }) + var f = facade.GetInstance("FacadeTestKey2", func() interfaces.IFacade { return &facade.Facade{Key: "FacadeTestKey2"} }) + f.RegisterCommand("FacadeTestNote", func() interfaces.ICommand { return &FacadeTestCommand{} }) // Send notification. The Command associated with the event // (FacadeTestCommand) will be invoked, and will multiply // the vo.input value by 2 and set the result on vo.result var vo = FacadeTestVO{Input: 32} - facade.SendNotification("FacadeTestNote", &vo, "") + f.SendNotification("FacadeTestNote", &vo, "") // test assertions if vo.Result != 64 { @@ -61,29 +61,29 @@ func TestRegisterCommandAndSendNotification(t *testing.T) { } /* - Tests Command removal via the Facade. +Tests Command removal via the Facade. - This test gets a Multiton Facade instance - and registers the FacadeTestCommand class - to handle 'FacadeTest' Notifcations. Then it removes the command. +This test gets a Multiton Facade instance +and registers the FacadeTestCommand class +to handle 'FacadeTest' Notifications. Then it removes the command. - It then sends a Notification using the Facade. - Success is determined by evaluating - a property on an object placed in the body of - the Notification, which will NOT be modified by the Command. +It then sends a Notification using the Facade. +Success is determined by evaluating +a property on an object placed in the body of +the Notification, which will NOT be modified by the Command. */ func TestRegisterAndRemoveCommandAndSendNotification(t *testing.T) { // Create the Facade, register the FacadeTestCommand to // handle 'FacadeTest' events - var facade = facade.GetInstance("FacadeTestKey3", func() interfaces.IFacade { return &facade.Facade{Key: "FacadeTestKey2"} }) - facade.RegisterCommand("FacadeTestNote", func() interfaces.ICommand { return &FacadeTestCommand{} }) - facade.RemoveCommand("FacadeTestNote") + var f = facade.GetInstance("FacadeTestKey3", func() interfaces.IFacade { return &facade.Facade{Key: "FacadeTestKey2"} }) + f.RegisterCommand("FacadeTestNote", func() interfaces.ICommand { return &FacadeTestCommand{} }) + f.RemoveCommand("FacadeTestNote") // Send notification. The Command associated with the event // (FacadeTestCommand) will NOT be invoked, and will NOT multiply // the vo.input value by 2 var vo = FacadeTestVO{Input: 32} - facade.SendNotification("FacadeTestNote", &vo, "") + f.SendNotification("FacadeTestNote", &vo, "") // test assertions if vo.Result == 64 { @@ -92,23 +92,23 @@ func TestRegisterAndRemoveCommandAndSendNotification(t *testing.T) { } /* - Tests the regsitering and retrieving Model proxies via the Facade. +Tests the regsitering and retrieving Model proxies via the Facade. - Tests registerProxy and retrieveProxy in the same test. - These methods cannot currently be tested separately - in any meaningful way other than to show that the - methods do not throw exception when called. +Tests registerProxy and retrieveProxy in the same test. +These methods cannot currently be tested separately +in any meaningful way other than to show that the +methods do not throw exception when called. */ func TestRegisterAndRetrieveProxy(t *testing.T) { // register a proxy and retrieve it. - var facade = facade.GetInstance("FacadeTestKey4", func() interfaces.IFacade { + var f = facade.GetInstance("FacadeTestKey4", func() interfaces.IFacade { return &facade.Facade{Key: "FacadeTestKey4"} }) - facade.RegisterProxy(&proxy.Proxy{Name: "colors", Data: []string{"red", "green", "blue"}}) - var proxy = facade.RetrieveProxy("colors").(*proxy.Proxy) + f.RegisterProxy(&proxy.Proxy{Name: "colors", Data: []string{"red", "green", "blue"}}) + var p = f.RetrieveProxy("colors").(*proxy.Proxy) // retrieve data from proxy - var data = proxy.Data.([]string) + var data = p.Data.([]string) // test assertions if data == nil { @@ -129,7 +129,7 @@ func TestRegisterAndRetrieveProxy(t *testing.T) { } /* - Tests the removing Proxies via the Facade. +Tests the removing Proxies via the Facade. */ func TestRegisterAndRemoveProxy(t *testing.T) { // register a proxy, remove it, then try to retrieve it @@ -156,7 +156,7 @@ func TestRegisterAndRemoveProxy(t *testing.T) { } /* - Tests registering, retrieving and removing Mediators via the Facade. +Tests registering, retrieving and removing Mediators via the Facade. */ func TestRegisterRetrieveAndRemoveMediator(t *testing.T) { // register a mediator, remove it, then try to retrieve it @@ -183,7 +183,7 @@ func TestRegisterRetrieveAndRemoveMediator(t *testing.T) { } /* - Tests the hasProxy Method +Tests the hasProxy Method */ func TestHasProxy(t *testing.T) { // register a Proxy @@ -198,7 +198,7 @@ func TestHasProxy(t *testing.T) { } /* - Tests the hasMediator Method +Tests the hasMediator Method */ func TestHasMediator(t *testing.T) { // register a Mediator @@ -221,7 +221,7 @@ func TestHasMediator(t *testing.T) { } /* - Test hasCommand method. +Test hasCommand method. */ func TestHasCommand(t *testing.T) { // register the ControllerTestCommand to handle 'hasCommandTest' notes @@ -245,7 +245,7 @@ func TestHasCommand(t *testing.T) { } /* - Tests the hasCore and removeCore methods +Tests the hasCore and removeCore methods */ func TestHasCoreAndRemoveCore(t *testing.T) { // assert that the Facade.hasCore method returns false first diff --git a/test/patterns/proxy/Proxy_test.go b/test/patterns/proxy/Proxy_test.go index 3b01253..4e3fab0 100755 --- a/test/patterns/proxy/Proxy_test.go +++ b/test/patterns/proxy/Proxy_test.go @@ -19,27 +19,27 @@ Test the PureMVC Proxy class. */ /* - Tests getting the name using Proxy class accessor method. Setting can only be done in constructor. +Tests getting the name using Proxy class accessor method. Setting can only be done in constructor. */ func TestNameAccessor(t *testing.T) { // Create a new Proxy and use accessors to set the proxy name - var proxy interfaces.IProxy = &proxy.Proxy{Name: "TestProxy", Data: nil} + var p interfaces.IProxy = &proxy.Proxy{Name: "TestProxy", Data: nil} // test assertions - if proxy.GetProxyName() != "TestProxy" { + if p.GetProxyName() != "TestProxy" { t.Error("Expecting proxy.GetProxyName() == 'TestProxy'") } } /* - Tests setting and getting the data using Proxy class accessor methods. +Tests setting and getting the data using Proxy class accessor methods. */ func TestDataAccessor(t *testing.T) { // Create a new Proxy and use accessors to set the data - var proxy interfaces.IProxy = &proxy.Proxy{Name: "colors"} - proxy.SetData([]string{"red", "green", "blue"}) + var p interfaces.IProxy = &proxy.Proxy{Name: "colors"} + p.SetData([]string{"red", "green", "blue"}) - var data = proxy.GetData().([]string) + var data = p.GetData().([]string) // test assertions if len(data) != 3 { @@ -57,19 +57,19 @@ func TestDataAccessor(t *testing.T) { } /* - Tests setting the name and body using the Notification class Constructor. +Tests setting the name and body using the Notification class Constructor. */ func TestConstructor(t *testing.T) { // Create a new Proxy using the Constructor to set the name and data - var proxy interfaces.IProxy = &proxy.Proxy{Name: "colors", Data: []string{"red", "green", "blue"}} + var p interfaces.IProxy = &proxy.Proxy{Name: "colors", Data: []string{"red", "green", "blue"}} - var data = proxy.GetData().([]string) + var data = p.GetData().([]string) // test assertions - if proxy == nil { + if p == nil { t.Error("Expecting proxy not nil") } - if proxy.GetProxyName() != "colors" { + if p.GetProxyName() != "colors" { t.Error("Expecting proxy.GetProxyName() == 'colors'") } if len(data) != 3 {