Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Info

The Command pattern is a behavioral design pattern in object-oriented programming (OOP) that encapsulates a request as an object, thereby allowing clients to parameterize clients with different requests, queue or log requests, and support undoable operations. It decouples the sender of a request from the receiver, allowing different types of requests to be handled in a uniform manner.

...

The Command pattern consists of several key components:

  • Command: Defines an interface for executing a specific operation. This interface typically includes a method like execute() that triggers the execution of the command.

  • Concrete Command: Implements the Command interface and represents a specific command or action. It encapsulates the receiver and binds the receiver with the action to be performed.

  • Receiver: Represents the object that receives the request and knows how to perform the actual operations.

  • Invoker: Requests the execution of a command by calling the execute() method defined in the Command interface. It does not know the specifics of the command or how the command is executed.

  • Client: Creates a command and sets its receiver, then passes the command to the invoker to execute.