Bird
0
0

How can you design the Board class to efficiently support different game variants with varying board sizes and piece sets?

hard📝 Trade-off Q9 of 15
LLD - Design — Chess Game
How can you design the Board class to efficiently support different game variants with varying board sizes and piece sets?
AHardcode board size and pieces inside the Board class
BCreate separate Board subclasses for each variant
CUse composition to inject board size and piece factory at runtime
DStore all pieces in a single global list
Step-by-Step Solution
Solution:
  1. Step 1: Understand flexibility needs

    Supporting variants requires configurable board size and piece creation.
  2. Step 2: Use composition and factories

    Injecting size and piece factory allows runtime customization without code changes.
  3. Final Answer:

    Use composition to inject board size and piece factory at runtime -> Option C
  4. Quick Check:

    Flexible design = composition + injection [OK]
Quick Trick: Inject configuration for flexible board design [OK]
Common Mistakes:
  • Hardcoding sizes limits flexibility
  • Creating many subclasses causes code duplication
  • Using global lists loses structure

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes