command

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2019 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MacroCommand

type MacroCommand struct {
	facade.Notifier
	SubCommands []func() interfaces.ICommand
}

A base ICommand implementation that executes other ICommands.

A MacroCommand maintains an list of ICommand Class references called SubCommands.

When execute is called, the MacroCommand retrieves ICommands by executing funcs and then calls execute on each of its SubCommands turn. Each SubCommand will be passed a reference to the original INotification that was passed to the MacroCommand's execute method.

Unlike SimpleCommand, your subclass should not override execute, but instead, should override the initializeMacroCommand method, calling addSubCommand once for each SubCommand to be executed.

func (*MacroCommand) AddSubCommand

func (self *MacroCommand) AddSubCommand(commandFunc func() interfaces.ICommand)

Add a SubCommand.

The SubCommands will be called in First In/First Out (FIFO) order.

- parameter func: reference that returns ICommand.

func (*MacroCommand) Execute

func (self *MacroCommand) Execute(notification interfaces.INotification)

Execute this MacroCommand's SubCommands.

The SubCommands will be called in First In/First Out (FIFO) order.

- parameter notification: the INotification object to be passsed to each SubCommand.

func (*MacroCommand) InitializeMacroCommand

func (self *MacroCommand) 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.

type SimpleCommand

type SimpleCommand struct {
	facade.Notifier
}

A base ICommand implementation.

Your subclass should override the execute method where your business logic will handle the INotification.

func (*SimpleCommand) Execute

func (self *SimpleCommand) Execute(notification interfaces.INotification)

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.

- parameter notification: the INotification to handle.

Jump to

Keyboard shortcuts

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