Bird
0
0

How would you design the Game class to support multiple types of board games (e.g., chess, checkers) using Board, Player, and Game classes?

hard📝 Trade-off Q8 of 15
LLD - Design — Tic-Tac-Toe Game
How would you design the Game class to support multiple types of board games (e.g., chess, checkers) using Board, Player, and Game classes?
AImplement all game logic inside the Board class only
BUse inheritance for Board and Player classes with a generic Game class
CCreate separate Game classes for each game type without shared code
DStore all game rules inside Player class methods
Step-by-Step Solution
Solution:
  1. Step 1: Consider extensibility

    Inheritance allows Board and Player to be specialized per game type while Game manages flow generically.
  2. Step 2: Evaluate other options

    Putting all logic in Board or Player reduces modularity; separate Game classes without shared code cause duplication.
  3. Final Answer:

    Use inheritance for Board and Player with generic Game class -> Option B
  4. Quick Check:

    Inheritance supports multiple game types [OK]
Quick Trick: Use inheritance for reusable game components [OK]
Common Mistakes:
MISTAKES
  • Putting all logic in one class
  • Duplicating code across game types

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes