What is the Command Pattern?

Updated Apr 28, 2026

Short answer

A behavioral pattern that turns a request into a stand-alone object that contains all information about the request.

Deep explanation

This transformation lets you pass requests as a method arguments, delay or queue a request's execution, and support undoable operations. It separates the object that invokes the operation from the one that knows how to perform it.

Real-world example

Implementing Undo/Redo functionality in a text editor. Every action (type, delete, paste) is a Command object pushed to a history stack.

Common mistakes

  • Creating a Command class for every tiny method, leading to severe class explosion.

Follow-up questions

  • How does Command relate to CQRS?

More Design Patterns interview questions

View all →