Author image

Command Design Pattern

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

You are not encapsulating the object that sends the request, or the object that receives the request, but encapsulate the actual request as an object with state. Of course, some commands can be stateless chunks of pure behavior (no data members).
The command pattern also makes undoable operations a piece of cake (they're considerably harder to implement wihout it). Derived Commands can leverage CRTP to be statically bound. To familiarize yourself with CRTP check this tutorial.

Note that the code executing the commands is responsible for freeing their memory.


  • define a base class or interface (abstract class)...