Bird
0
0

Why is it important to keep the Piece class hierarchy open for extension but closed for modification in board game design?

hard📝 Conceptual Q10 of 15
LLD - Design — Chess Game
Why is it important to keep the Piece class hierarchy open for extension but closed for modification in board game design?
ATo make the base class as large as possible
BTo prevent any new pieces from being added
CTo allow adding new pieces without changing existing code
DTo force rewriting the entire game for new pieces
Step-by-Step Solution
Solution:
  1. Step 1: Understand open-closed principle

    It states software entities should be open for extension but closed for modification.
  2. Step 2: Apply to piece hierarchy

    This allows adding new piece types by subclassing without changing tested existing code.
  3. Final Answer:

    To allow adding new pieces without changing existing code -> Option C
  4. Quick Check:

    Open-closed principle = extend without modify [OK]
Quick Trick: Extend classes, don't modify existing ones [OK]
Common Mistakes:
  • Thinking no new pieces allowed
  • Believing entire rewrite is needed
  • Making base class too complex

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes