Bird
0
0

What is the main purpose of the Command pattern in the context of undo functionality?

easy🧠 Conceptual Q11 of 15
LLD - Design — Tic-Tac-Toe Game
What is the main purpose of the Command pattern in the context of undo functionality?
ATo replace all conditional statements with loops
BTo directly modify the user interface without storing history
CTo store data in a database for permanent record
DTo encapsulate actions as objects with execute and undo methods
Step-by-Step Solution
Solution:
  1. Step 1: Understand the role of Command pattern

    The Command pattern wraps actions as objects, allowing them to be executed and undone independently.
  2. Step 2: Relate to undo functionality

    This wrapping enables storing commands in a history stack, so undo can call the undo method on the last command.
  3. Final Answer:

    To encapsulate actions as objects with execute and undo methods -> Option D
  4. Quick Check:

    Command pattern = encapsulate actions for undo [OK]
Quick Trick: Command pattern wraps actions for undo/redo [OK]
Common Mistakes:
MISTAKES
  • Thinking Command pattern modifies UI directly
  • Confusing Command pattern with data storage
  • Assuming it replaces loops or conditionals

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes