What is the Liskov substitution principle, and why can a square-as-rectangle hierarchy violate it?
Interactive Practice Mode
Formulate your thoughts or take notes before revealing the model solution.
Saved automatically
Model Answer & Deep-Dive Explanation
A subtype must be usable wherever its parent is expected without breaking the parent’s behavioral contract. If a mutable rectangle promises independently settable width and height, a square that changes both when either is set violates that expectation. Code that sets width to 5 and height to 4 expects area 20, but receives a different result. The mathematical relationship does not automatically justify a mutable object hierarchy. An immutable shape abstraction exposing area, or separate rectangle and square types, can avoid the conflicting contract.
Related Questions in Software Engineering & OOP
Explain the SOLID Principles of Object-Oriented Software Engineering with Examples
Intermediate level • 715 views
What are the core SaaS business and engineering metrics (CAC, LTV, MRR, Churn, NRR), and why do developers need to understand them?
Beginner level • 320 views
What is Multi-Tenant Architecture in SaaS, and how do database tenancy models differ?
Intermediate level • 318 views
How do SaaS platforms handle cross-region multi-master data replication and conflict resolution (CRDTs)?
Advanced level • 298 views
Explain ACID properties in relational databases and how different Transaction Isolation Levels prevent concurrency anomalies.
Intermediate level • 250 views