Bird
Raised Fist0

What is a common trade-off or limitation when strictly enforcing the Liskov Substitution Principle in a large inheritance hierarchy?

medium🪤 Complexity Trap Q13 of Q15
OOP & Design Patterns - Liskov Substitution Principle - Subtype Behavioural Contract
What is a common trade-off or limitation when strictly enforcing the Liskov Substitution Principle in a large inheritance hierarchy?
AIt can lead to overly rigid designs that prevent useful specialization.
BIt always improves code flexibility and reduces bugs without downsides.
CIt allows subclasses to freely change method signatures for optimization.
DIt eliminates the need for interface segregation.
Step-by-Step Solution
  1. Step 1: Understand strict LSP enforcement

    Strict LSP means subclasses cannot alter behavior or method contracts in incompatible ways.
  2. Step 2: Analyze trade-offs

    This can restrict subclass implementations, making designs rigid and limiting specialization.
  3. Step 3: Evaluate options

    It can lead to overly rigid designs that prevent useful specialization. correctly identifies rigidity as a trade-off. It always improves code flexibility and reduces bugs without downsides. is false; strict LSP can reduce flexibility. It allows subclasses to freely change method signatures for optimization. is incorrect; method signatures must respect variance rules. It eliminates the need for interface segregation. is false; interface segregation addresses different concerns.
  4. Final Answer:

    Option A -> Option A
  5. Quick Check:

    Strict LSP can constrain subclass design choices.
Quick Trick: Strict LSP enforces substitutability but can limit subclass flexibility.
Common Mistakes:
MISTAKES
  • Believing strict LSP has no downsides
  • Confusing LSP with interface segregation
  • Assuming method signatures can be freely changed
Trap Explanation:
PITFALL
  • Options B and C reflect over-optimistic or incorrect beliefs about LSP; option A confuses separate SOLID principles.
Interviewer Note:
CONTEXT
  • Tests candidate's understanding of practical trade-offs and limitations of LSP.
Master "Liskov Substitution Principle - Subtype Behavioural Contract" in OOP & Design Patterns

2 interactive learning modes - each teaches the same concept differently

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More OOP & Design Patterns Quizzes