Bird
Raised Fist0

When enforcing the Liskov Substitution Principle (LSP) in a deep class hierarchy, what is a typical challenge developers face?

medium💡 Conceptual Thinking Q5 of Q15
OOP & Design Patterns - Liskov Substitution Principle - Subtype Behavioural Contract
When enforcing the Liskov Substitution Principle (LSP) in a deep class hierarchy, what is a typical challenge developers face?
AInability to override any methods in subclasses
BIncreased complexity in maintaining consistent behavioral contracts across all subclasses
CMandatory use of interfaces instead of abstract classes
DComplete elimination of polymorphism
Step-by-Step Solution
Solution:
  1. Step 1: Understand LSP enforcement

    Strict LSP enforcement requires subclasses to honor all behavioral contracts of their superclasses.
  2. Step 2: Analyze impact on deep hierarchies

    In deep inheritance trees, ensuring all subclasses comply with these contracts becomes increasingly complex and error-prone.
  3. Final Answer:

    Option B -> Option B
  4. Quick Check:

    Maintaining behavioral consistency is harder with more subclasses [OK]
Quick Trick: More subclasses mean harder contract maintenance [OK]
Common Mistakes:
MISTAKES
  • Believing that LSP forbids any method overriding
  • Assuming interfaces must replace abstract classes due to LSP
  • Thinking LSP eliminates polymorphism entirely
Trap Explanation:
PITFALL
  • Options B, C, and D incorrectly imply LSP restricts fundamental OOP features.
Interviewer Note:
CONTEXT
  • Tests understanding of practical challenges in applying LSP in complex hierarchies.
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