Definition
It is a behavioural pattern that encapsulates requests into objects. Thus clients can be parameterized with different requests which can also be queued and logged which allows for undoing actions.
GoF Template
-
Command: This is an interface or abstract class that defines the
execute
method, which encapsulates a specific action. -
Concrete Command: These are the concrete implementations of the
Command
interface, each encapsulating a specific action and maintaining a reference to the object that performs the action (the receiver). -
Receiver: This is the object that actually performs the action when the
execute
method of a command is called. -
Invoker: This is responsible for maintaining a collection of commands and calling their
execute
methods.