Bird
0
0

A system uses nested if-else statements everywhere instead of polymorphism to handle different behaviors. Which anti-pattern does this represent and why is it problematic?

hard📝 Trade-off Q9 of 15
LLD - Advanced LLD Concepts
A system uses nested if-else statements everywhere instead of polymorphism to handle different behaviors. Which anti-pattern does this represent and why is it problematic?
AMagic Numbers; it uses unexplained constants
BGod Object; it centralizes all logic in one place
CShotgun Surgery; it requires many changes for one feature
DSwitch Statements Anti-pattern; it reduces extensibility and increases complexity
Step-by-Step Solution
Solution:
  1. Step 1: Identify nested if-else problem

    Using many if-else instead of polymorphism is called Switch Statements Anti-pattern.
  2. Step 2: Understand why problematic

    This reduces extensibility and makes code complex to maintain, matching Switch Statements Anti-pattern; it reduces extensibility and increases complexity.
  3. Final Answer:

    Switch Statements Anti-pattern; it reduces extensibility and increases complexity -> Option D
  4. Quick Check:

    Nested if-else vs polymorphism = Switch Statements Anti-pattern [OK]
Quick Trick: Replace nested if-else with polymorphism [OK]
Common Mistakes:
  • Confusing with God Object
  • Thinking magic numbers relate here
  • Mixing with shotgun surgery

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes