Bird
Raised Fist0

Why is polymorphism preferred over using large conditional statements to implement piece movement rules?

hard🧠 Conceptual Q10 of Q15
LLD - Design — Chess Game
Why is polymorphism preferred over using large conditional statements to implement piece movement rules?
AConditional statements run faster than polymorphic calls.
BPolymorphism improves code maintainability and scalability by avoiding complex conditionals.
CPolymorphism requires more code duplication.
DConditional statements are easier to extend with new pieces.
Step-by-Step Solution
Solution:
  1. Step 1: Compare polymorphism and conditional statements

    Large conditionals become hard to maintain and extend as new pieces are added.
  2. Step 2: Benefits of polymorphism

    Polymorphism allows adding new piece classes with their own move methods without changing existing code.
  3. Final Answer:

    Polymorphism improves code maintainability and scalability by avoiding complex conditionals. -> Option B
  4. Quick Check:

    Polymorphism = cleaner, scalable code [OK]
Quick Trick: Polymorphism avoids messy conditionals for easier scaling [OK]
Common Mistakes:
MISTAKES
  • Believing conditionals are easier to extend
  • Thinking polymorphism duplicates code
  • Assuming conditionals are always faster

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes