Loading lesson…
Level 1 · Apprentice0 XP
Save and restore an object's state without exposing its internals: undo, drafts and snapshots.
Step 1 / 5
ProblemA drawing editor lets users move shapes. Users ask for undo. The editor's fields are private, and copying them from outside would break encapsulation.
← → step
Before this: Mediator
🛠️ Your turn
Reading is not the skill, doing is. Try for ten minutes before you open the hint. Getting stuck first is what makes the solution stick.
1.Add undo and redo to a small text editor using immutable state and two stacks, capped at 50 entries. Test undo after five edits and redo after two undos.