Bird
0
0

You want to add a new piece type Wizard with special moves to an existing board game. Which design approach best fits this addition?

hard📝 Trade-off Q8 of 15
LLD - Design — Chess Game
You want to add a new piece type Wizard with special moves to an existing board game. Which design approach best fits this addition?
AAdd Wizard moves directly inside the Board class
BCreate a new subclass <code>Wizard</code> extending <code>Piece</code> and override move logic
CModify the base <code>Piece</code> class to include Wizard moves
DUse a global function to handle Wizard moves separately
Step-by-Step Solution
Solution:
  1. Step 1: Consider extensibility

    Adding new piece types is best done by subclassing to keep code modular.
  2. Step 2: Why not modify base or board?

    Changing base class or board breaks existing code and mixes responsibilities.
  3. Final Answer:

    Create a new subclass Wizard extending Piece and override move logic -> Option B
  4. Quick Check:

    New piece addition = subclass + override [OK]
Quick Trick: Add new pieces by subclassing base Piece class [OK]
Common Mistakes:
  • Changing base class for new piece
  • Putting piece logic in Board class
  • Using global functions for piece moves

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes