Bird
0
0

Which design choice best supports adding new game rules and multiple player types (e.g., human, AI) without changing existing code much?

hard📝 Trade-off Q15 of 15
LLD - Design — Tic-Tac-Toe Game
You want to design a turn-based game system using Board, Player, and Game classes. Which design choice best supports adding new game rules and multiple player types (e.g., human, AI) without changing existing code much?
AUse global variables for player types and rules to simplify access
BKeep all logic inside Game class and add if-else for player types and rules
CUse inheritance: create subclasses like HumanPlayer and AIPlayer from Player, and extend Game with rule classes
DStore all player and rule info in Board class to centralize state
Step-by-Step Solution
Solution:
  1. Step 1: Consider extensibility and separation of concerns

    Inheritance allows creating specialized Player types without modifying base Player class, supporting new behaviors.
  2. Step 2: Use modular design for rules

    Extending Game with separate rule classes or modules keeps code clean and easy to maintain.
  3. Final Answer:

    Use inheritance: create subclasses like HumanPlayer and AIPlayer from Player, and extend Game with rule classes -> Option C
  4. Quick Check:

    Inheritance and modular rules = easy extension [OK]
Quick Trick: Use inheritance and modular rules for easy feature addition [OK]
Common Mistakes:
MISTAKES
  • Putting all logic in one class causing messy code
  • Using global variables leading to hard-to-maintain code
  • Storing rules in Board instead of Game

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes