Glossary

Command Pattern

Command is a pattern that encapsulates a request as an object. The sender does not know who will execute the command or how — it simply calls execute(). This enables queuing, logging, and undoing commands.

Participants

Example

interface Command {
  public function execute(): void;
  public function undo(): void;
}

class SendEmailCommand implements Command {
  public function execute(): void { /* send */ }
  public function undo(): void { /* cancel */ }
}

class CommandBus {
  private array $history = [];
  public function dispatch(Command $cmd): void {
    $cmd->execute();
    $this->history[] = $cmd;
  }
}

Where used

CQRS (Command Bus), task queues, transaction script, undo/redo in editors.