Bird
Raised Fist0

In a Command pattern implementation, what common error can cause the undo operation to not revert changes as expected?

medium📝 Analysis Q6 of Q15
LLD - Design — Tic-Tac-Toe Game
In a Command pattern implementation, what common error can cause the undo operation to not revert changes as expected?
ANot saving the state before executing the command
BCalling undo before execute
CUsing a queue instead of a stack to store commands
DImplementing undo as a static method
Step-by-Step Solution
Solution:
  1. Step 1: Understand undo requirements

    Undo needs to restore the previous state before the command execution.
  2. Step 2: Identify common mistake

    If the state isn't saved prior, undo cannot revert changes properly.
  3. Final Answer:

    Not saving the state before executing the command -> Option A
  4. Quick Check:

    Undo requires prior state saved [OK]
Quick Trick: Undo needs saved state before execution [OK]
Common Mistakes:
MISTAKES
  • Undo called before execute
  • Using wrong data structure for command history
  • Making undo static causing state issues

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes