Definition of a Macro: “An object that contains a symbol, name or key that represents a list of commands, actions or keystrokes”. This is the basis of the Command design pattern.
The Command Pattern encapsulates commands (method calls) in objects, allowing us to issue requests without knowing the requested operation or the requesting object. This pattern provides the options to queue commands, undo/redo actions etc.
- Encapsulate a request in an object
- Allows the parameterization of clients with different requests
- Allows saving the requests in a queue
The classes participating in the pattern are:
- declares an interface for executing an operation
- extends the Command interface, implementing the Execute method by invoking the corresponding operations on Receiver. It defines a link between the Receiver and the action.
- creates a ConcreteCommand object and sets its receiver
- asks the command to carry out the request
- knows how to perform the operations
The Client asks for a command to be executed. The Invoker takes the command, encapsulates it and places it in a queue, in case there is something else to do first, and the ConcreteCommand that is in charge of the requested command, sending its result to the Receiver.
I’ve basically nicked all this, word for word, from the source below but it seemed pointless to reword and rework it too much. It’s good info.