core practice · system design prompt

Undo / redo stack

Design undo/redo for a text editor using the Command pattern. Each user action becomes a Command with execute/undo. Decide how the redo stack interacts with new edits.

The mechanism

The command pattern turns an action into a small object you can store, queue, log, or reverse. Pair it with two stacks for undo/redo, with a queue for background jobs, or with a chain for middleware-style processing.

Study Command & Chain

Expected evidence

Command interface + 2-3 concrete commands + the two stacks and their invariants.

Try this drill in the practice workspace →

Hints when you need them
  • New action after undo should clear the redo stack.
  • Group small typing actions into one Command for usability.

Check the sources

Browse all practice briefs