Bird
0
0

Why is it important for Command objects to be immutable or carefully manage state when supporting undo?

hard🧠 Conceptual Q10 of 15
LLD - Design — Tic-Tac-Toe Game
Why is it important for Command objects to be immutable or carefully manage state when supporting undo?
ATo improve performance by skipping undo steps.
BTo allow commands to be reused for different actions.
CTo ensure undo restores the exact previous state without side effects.
DTo prevent commands from being stored in history.
Step-by-Step Solution
Solution:
  1. Step 1: Understand state consistency in undo

    Undo must restore system to exact previous state before command execution.
  2. Step 2: Role of immutability or state management

    If command state changes unexpectedly, undo may fail or cause side effects.
  3. Final Answer:

    To ensure undo restores the exact previous state without side effects. -> Option C
  4. Quick Check:

    Undo correctness = immutable command state [OK]
Quick Trick: Immutable commands ensure reliable undo [OK]
Common Mistakes:
MISTAKES
  • Thinking commands should be reusable for different actions
  • Assuming performance gains by skipping undo
  • Believing commands shouldn't be stored

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes