Design Patterns · Middle · Question 7 of 75

How do you implement undo/redo with the Command pattern?

Explanation

An executed command goes onto the undo stack; undoing calls undo() and moves the command to the redo stack. A new action clears redo. An alternative for immutable state is the Memento pattern: keep previous versions of the state.

Further reading

Problem with a question

Design Patterns · Middle · question 7

Test yourself

Take the Design Patterns · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz