What the command pattern is
The command pattern is a software design pattern in which a request or action is turned into a standalone object. This object, the command, contains everything needed to perform the action. Because the request is now an object, it can be stored, passed around, and executed later, rather than being carried out immediately as a direct call. This adds flexibility in how actions are handled.
A request as an object
Normally, performing an action means calling a method directly. The command pattern instead wraps that action in an object. The command object knows what to do and holds any information the action needs. Turning a request into an object in this way means the action can be treated as data: handed to other code, kept in a list, or triggered at a chosen time.
Storing and queuing actions
Because commands are objects, they can be collected and managed. A program can keep a queue of commands to run, or a history of commands that have been executed. This makes it possible to schedule actions, run them in order, or keep track of what has been done. The ability to hold actions as objects opens up these kinds of flexible handling.
Enabling features like undo
One well-known benefit of the command pattern is that it can support features such as undo. If each action is a command object, a program can remember the sequence of commands and reverse them when needed. By keeping actions as discrete objects with known effects, the pattern makes it practical to manage and even roll back what has happened, which is harder with direct calls.
Command among design patterns
The command is one of the classic design patterns for organizing behavior. Describing something as a command pattern conveys that requests are wrapped as objects that can be stored and executed later. Recognizing this pattern helps developers build flexible systems for handling actions and discuss how requests flow through a program.
Why it matters
The command pattern is a valuable design pattern for handling actions flexibly. Understanding what it is - turning a request into an object that can be stored and run later - clarifies how features like queuing and undo are built. For anyone learning software design, it is a valuable concept to understand.
Related on Skillo
See also: What is a design pattern? Explained, What is the observer pattern? Explained.
Sources
Published date reflects the original event date (2026-03-03). This article is original Skillo editorial written from the sources above; facts were verified in September 2026.
Leave a Reply