Commands

Commands are the means by which a user communicates with an application. They originate from sources in the user interface and are then routed to objects that perform an appropriate action for the command.

What is a command?

Currently a command object is a Symbol that represents the method selector that will be sent to perform the eventual operation (in future this may change and a Command class may be introduced).

Where do commands originate?

Commands originate in a variety of sources within the user interface. These include:

These sources are all in the view-controller layer of the framework; they are either controllers themselves (PushButtonController) or are owned by views (CommandMenuItem, ToolbarButton). This makes sense, since the only interface a user has to an application is via the GUI layer. In either case the command is directly passed to a controller which is responsible for routing it to an eventual destination where it can be performed.

Command routing

The framework automatically handles the routing of commands through to their destinations such that they invoke an appropriate method. The destination may be in the view-controller layer, the tool layer or the domain layer of the application. It is important, therefore, to have a consistent but flexible way of ensuring these commands reach the correct targets.

The framework uses an instance of CommandPolicy to encapsulate the routing algorithm. All controllers have access to an appropriate command policy that they use to route their commands via their #commandPolicy method.

Changing the way commands are routed

The default implementation of this answers the single instance of CommandPolicy from CommandPolicy class>>default which implements a general purpose routing scheme.