Skip to main content

No Undo/Redo History

Description​

What does it look like?​

  • User actions are not recorded, so undo/redo functionality is unavailable
  • There is no way to revert the side effects of an operation
  • Without a history, it is difficult to restore or roll back system state

Why is it a problem?​

  • Poor user experience (UX) β€” no way to undo mistakes
  • Recovery from input errors requires redoing or restoring manually
  • Difficult to debug or trace issues in complex state changes

Bad Example of the Anti-pattern​

class TextEditor {
private content: string = "";

type(text: string) {
this.content += text;
}

getContent() {
return this.content;
}
}

const editor = new TextEditor();
editor.type("Hello ");
editor.type("World");

console.log(editor.getContent()); // Hello World

// ε–γ‚ŠζΆˆγ—γŒγ§γγͺい!

Issues:​

  • Input is applied directly to the internal state β€” no way to undo
  • type() modifies the content immediately, making history management difficult

Refactoring by Pattern​

Design patterns that can address this​

PatternOverviewMain Refactoring Approach
CommandEncapsulate operations as command objects and manage execute/undo/redoStore and control execution history
MementoCapture and restore full snapshots of an object’s stateEnable complete state restoration