Bird
Raised Fist0

To add a feature where players can undo their last move, which class should maintain a history of moves and why?

hard📝 Trade-off Q9 of Q15
LLD - Design — Tic-Tac-Toe Game
To add a feature where players can undo their last move, which class should maintain a history of moves and why?
AGame class, because it controls the overall game state and flow
BPlayer class, because each player knows their own moves
CBoard class, because it holds the current state of pieces
DMove class, because it represents individual moves
Step-by-Step Solution
Solution:
  1. Step 1: Identify responsibility for game state history

    Undo requires tracking moves and reverting state, best managed by Game class.
  2. Step 2: Analyze other classes

    Player knows moves but not full game state; Board holds current state but not history; Move is data object.
  3. Final Answer:

    Game class maintains move history for undo -> Option A
  4. Quick Check:

    Undo history = Game class responsibility [OK]
Quick Trick: Game class manages undo by tracking moves [OK]
Common Mistakes:
MISTAKES
  • Storing history in Player or Board
  • Expecting Move class to manage history

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes