LLMpediaThe first transparent, open encyclopedia generated by LLMs

Liskov substitution principle

Generated by GPT-5-mini
Note: This article was automatically generated by a large language model (LLM) from purely parametric knowledge (no retrieval). It may contain inaccuracies or hallucinations. This encyclopedia is part of a research project currently under review.
Article Genealogy
Parent: Barbara Liskov Hop 4
Expansion Funnel Raw 92 → Dedup 0 → NER 0 → Enqueued 0
1. Extracted92
2. After dedup0 (None)
3. After NER0 ()
4. Enqueued0 ()
Liskov substitution principle
NameLiskov substitution principle
FieldComputer science
Introduced1987
Introduced byBarbara Liskov
RelatedSOLID, object-oriented programming, subtype polymorphism

Liskov substitution principle

The Liskov substitution principle is a software design guideline in Computer science and Software engineering that constrains subtype relationships so that objects of a subtype can replace objects of a supertype without altering desirable properties of a program. It originated in research on programming languages and type theory and has influenced practices in Object-oriented programming, Design patterns, and Software architecture.

Overview and Definition

Barbara Liskov articulated the principle in a 1987 conference presentation at ACM SIGPLAN venues, building on earlier work in type theory and program verification. The principle states informally that if S is a subtype of T, then objects of type S should be replaceable for objects of type T without affecting correctness in clients that use T, tying into notions from Alonzo Church, Alan Turing, John McCarthy, and the development of formal semantics at institutions like MIT and Carnegie Mellon University. It is often cited together with the other principles that form SOLID, and is taught in curricula at Stanford University, Massachusetts Institute of Technology, and University of California, Berkeley.

History and Origin

The principle grew from Liskov's work published in proceedings of ACM conferences and collaborations with students and colleagues at Massachusetts Institute of Technology and Brown University. Early antecedents include formalizations of subtyping by researchers at Bell Labs, IBM Research, and Xerox PARC, and ties to verification systems such as Hoare logic and the Z notation used at Oxford University. Key influences include the development of Simula at the Norwegian Computing Center, ALGOL research in Zurich, and later object-oriented languages like Smalltalk, C++, and Java that made subtype relationships central to large-scale software development. The principle was popularized through textbooks by authors associated with Addison-Wesley and O'Reilly Media as object-oriented design became mainstream in industry players like Microsoft and Sun Microsystems.

Formal Statement and Examples

Formally, the principle can be expressed using behavioral subtyping and preconditions/postconditions from predicate logic and Hoare logic: a subtype must not strengthen preconditions nor weaken postconditions of the supertype's operations. This formalism connects to work by researchers at Princeton University, University of Cambridge, and ETH Zurich on type systems and contracts. Classic examples contrast types such as a Rectangle and a Square in educational materials from Carnegie Mellon University and University of Toronto, and collections like List and Set in libraries developed at Google and Apache Software Foundation. Real-world API examples appear in frameworks from Spring Framework, Microsoft .NET Framework, and Ruby on Rails, illustrating how violating the formal constraints can lead to unexpected behavior in clients at companies like Facebook and Amazon.

Design and Implementation Implications

Adhering to the principle affects class hierarchy design, interface definition, and testing strategies used by teams at Netflix, Airbnb, and LinkedIn. It motivates using composition over inheritance in cases emphasized by proponents at ThoughtWorks and authors associated with Pragmatic Bookshelf. Static analysis tools from JetBrains, Coverity, and SonarSource incorporate checks inspired by behavioral subtyping, while runtime design by contract systems from Eiffel and D language implement contract assertions to enforce pre/postcondition rules. Large-scale systems at Google and Apple adopt module boundaries and API versioning practices to maintain substitutability across releases.

Violations and Common Pitfalls

Common violations include strengthening preconditions in subtypes, weakening postconditions, and altering expected invariants, issues documented in case studies from IBM, Oracle Corporation, and academic analyses at University of Illinois Urbana–Champaign. Pitfalls occur when developers misuse inheritance for code reuse in projects at Yahoo and eBay, or when frameworks like Hibernate or Entity Framework expose mutable state that breaks client assumptions. Debugging such violations often involves test suites influenced by methodologies from Kent Beck and Martin Fowler and tooling from JUnit and pytest.

Relationship to Other SOLID Principles

The principle is one member of the SOLID acronym alongside the Single responsibility principle, Open–closed principle, Interface segregation principle, and Dependency inversion principle. Together, these principles are discussed in literature from Robert C. Martin and featured in courses at Columbia University and Imperial College London, influencing software practices at organizations such as Spotify and GitHub. While Liskov substitution emphasizes behavioral correctness of subtypes, other SOLID principles address cohesion, extensibility, interface design, and dependency management, with complementary guidance drawn from works by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides.

Category:Software design principles