# Undo and Redo with Commands

An undo button that remembers only the last change can't take back two mistakes, and can't redo anything; when each command knows how to reverse itself, a stack of done commands and a stack of undone ones give the dispatcher as many undos and redos as she needs.

![Cheat sheet: Undo and Redo with Commands](https://fsdtrainingmedia.blob.core.windows.net/public/images/2026/11/b66a03b741044f068fb8b7cc0bd386fb.webp)

- Category: Data Structures
- Level: Journeyman
- Tags: "Last In", "First Out", Command Pattern, OOP, stack
- Author: Gregor Dzierzon
- Updated: November 17, 2026

Source: https://www.ask-codey.com/cheat-sheets/dp-undo-redo-cheat-sheet
