liveBook · Manning

Liskov Substitution Principle

Also called LSP

The Liskov Substitution Principle is a design principle requiring subtype instances to be usable wherever supertype instances are expected without violating behavioral expectations or program correctness.

How 6 Manning books explain it

Grokking Software Architecture

The Liskov Substitution Principle is an object-oriented design principle requiring instances of a subtype to remain behaviorally usable wherever instances of its parent type are expected.

How it is used
Uses behavioral substitution as a SOLID design check for trustworthy shared contracts.
How deep it goes
Explains the principle through a behavioral contract and contrasting subclass implementations.
Examples
Illustrates a goalie substituted for a field player and checkout code coupled to one payment provider.
What you can do after
Evaluate whether a child class fulfills its parent’s behavioral contract for callers.

Read how Grokking Software Architecture explains Liskov Substitution Principle →

Object-Oriented Software Design in C++

The Liskov Substitution Principle states that objects of a subclass should be usable wherever objects of its superclass are expected without violating correctness.

How it is used
Guides the design and review of superclass-subclass hierarchies so inherited objects remain safely interchangeable.
How deep it goes
Explains substitution, overriding contracts, and a failing CircularBuffer implementation before refactoring toward aggregation.
Examples
Uses GeneralTax and LocalTax substitution, then contrasts vector-inherited and vector-contained CircularBuffer implementations.
What you can do after
Evaluate subclass designs, preserve overriding contracts, and refactor invalid inheritance toward composition or aggregation.

Read how Object-Oriented Software Design in C++ explains Liskov Substitution Principle →

Go in Action, Second Edition

The Liskov substitution principle states that objects of a subtype should be usable wherever objects of its supertype are expected without invalidating program correctness.

How it is used
Uses interfaces to keep domain consumers independent from feed readers, storage systems, and testing implementations.
How deep it goes
Explains substitution through Go interfaces, narrowed dependencies, and production-versus-test implementations, without detailing formal behavioral contracts.
Examples
Demonstrates Fetcher, Storage, ArticleReader, BoltStore, RSSReader, MockFetcher, and isolated HTTP handler tests.
What you can do after
Apply interface substitution to inject production stores, feed readers, mocks, and test doubles without changing consuming packages.

Read how Go in Action, Second Edition explains Liskov Substitution Principle →

Software Design for Python Programmers

The Liskov Substitution Principle is a design principle requiring objects of subclasses to be substitutable for objects of their superclass without invalidating program correctness.

How it is used
Guides the design of proper subclasses within object-oriented class hierarchies.
How deep it goes
Explains substitution through a failing CircularBuffer example and a refactoring, without developing formal contract rules in detail.
Examples
Uses a Python CircularBuffer subclass of list, invalid indexing and pop operations, and a private-list refactoring.
What you can do after
Diagnose subclass designs that permit invalid inherited operations and refactor them toward a suitable class relationship.

Read how Software Design for Python Programmers explains Liskov Substitution Principle →

Practices of the Python Pro

The Liskov substitution principle states that objects of a subtype must be replaceable for objects of its supertype without impairing program correctness.

How it is used
Checks whether inheritance preserves interchangeable roles and program correctness.
How deep it goes
Defines substitution, tests signatures and exceptions, and contrasts inheritance with composition through short Python examples.
Examples
Uses Slug and Snail, Bird and Penguin, and a Bicycle model exercise.
What you can do after
Diagnose inheritance designs by checking replacement behavior and choosing composition when specialization cannot preserve expectations.

Read how Practices of the Python Pro explains Liskov Substitution Principle →

Functional Design and Architecture: Examples in Haskell

A design principle requiring objects substituted for an abstraction to preserve the behavioral expectations of clients using that abstraction.

How it is used
Uses behavioral contracts to keep polymorphic client code unchanged when implementations are substituted.
How deep it goes
Explains substitution through an interface and a concrete failure, stopping short of formal contract rules.
Examples
Uses ILampSwitcher, DaylightLamp, TableLamp, and a turnAllOff client to demonstrate valid and broken substitution.
What you can do after
Diagnose substitution violations by checking whether an implementation preserves the interface behavior clients rely on.

Read how Functional Design and Architecture: Examples in Haskell explains Liskov Substitution Principle →

Also covered in

What to know first

Related concepts

Questions about Liskov Substitution Principle

What is Liskov Substitution Principle?

The Liskov Substitution Principle is a design principle requiring subtype instances to be usable wherever supertype instances are expected without violating behavioral expectations or program correctness.

Which Manning books explain Liskov Substitution Principle?

Grokking Software Architecture, Object-Oriented Software Design in C++, Go in Action, Second Edition, Software Design for Python Programmers, Practices of the Python Pro and Functional Design and Architecture: Examples in Haskell.

What should I know before learning Liskov Substitution Principle?

Manning books that teach Liskov Substitution Principle usually introduce inheritance, coupling, interface and object-oriented programming first.

What is the difference between Liskov Substitution Principle and concrete type?

The Liskov Substitution Principle is a design principle requiring subtype instances to be usable wherever supertype instances are expected without violating behavioral expectations or program correctness. A concrete type is a fully specified, directly implementable or instantiable type with a particular representation and behavior.

What is Liskov Substitution Principle part of?

Liskov Substitution Principle is part of SOLID principles. The SOLID principles are five object-oriented software design guidelines concerning responsibility, extensibility, substitutability, interface design, and dependency direction.

What is Liskov Substitution Principle also called?

Liskov Substitution Principle is also called LSP.

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.