The Command pattern is a behavioral GoF design pattern by Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides that encapsulates a request as an object. Because each action becomes an object, clients can be parameterized with different requests, and requests can be queued, logged or scheduled. Commands also support undoable operations, which makes the pattern a common basis for undo and redo systems.

GoF-Command Pattern

Details
Full Name

GoF Command Pattern (Behavioral)

Intent:

Encapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations.

When to Use:

  • When you want to parameterize objects with an action to perform

  • When you need undo/redo functionality

  • When you need to queue, log, or schedule requests

Prompt Example:

"Implementiere ein Undo/Redo-System nach dem GoF-Command Pattern, bei dem jede Benutzeraktion als Command-Objekt gekapselt wird."