# Command Pattern

A pattern that turns an action into an object so it can be queued or undone.

## What is **Command Pattern**?

The **Command pattern** turns an action into an object, so it can be stored, queued, logged or undone. Text editors use it for undo and redo.

```csharp
public interface ICommand { void Execute(); void Undo(); }

var history = new Stack<ICommand>();
var bold = new MakeBoldCommand(document, selection);
bold.Execute();
history.Push(bold);
```

Level: Master · [More OOP terms at this level](https://www.ask-codey.com/glossary/subjects/oop/master)

Updated: September 27, 2026

Source: https://www.ask-codey.com/glossary/command-pattern
