Design an Undo/Redo Framework for a Document Editor

Problem

Design the undo/redo system for a document editor like Adobe Acrobat or InDesign.

Requirements

  • executeCommand(cmd) — execute and push to undo stack
  • undo() — reverse the last command
  • redo() — re-apply the last undone command
  • Support grouping: beginTransaction() / commitTransaction() — entire group is undone together
  • Command history limit (e.g., last 50 actions)

Design pattern

Command Pattern — each operation is encapsulated as an object with execute() and undo() methods.

Classes expected

Command (interface), InsertTextCommand, DeleteTextCommand, FormatCommand, CompositeCommand, CommandHistory

Extension

Add collaborative editing: two users on the same document, how does undo interact with remote changes? (Operational Transformation hint)

added …
LeaderboardSalaryAccount