Skip to content

Subtyping and Substitutability

When type S is a subtype of T, values of type S can safely be used wherever T is expected - defining the rules for when one type can substitute for another without breaking program correctness.

Tension Addressed

Expressiveness vs. Simplicity

Recognizable As

Inheritance hierarchies; interface implementation; "a Dog is-a Animal"; covariance and contravariance rules; Liskov Substitution Principle violations

Canonical Sources

Liskov, "Data Abstraction and Hierarchy" (1987); Cardelli, "A Semantics of Multiple Inheritance" (1988); Liskov & Wing, "A Behavioral Notion of Subtyping" (1994)

Transfers To

API versioning (backward compatibility), contract design (what guarantees subtypes must preserve), any hierarchical classification system

Subtyping formalizes when substitution is safe. The Liskov Substitution Principle articulates the behavioral requirements: subtypes must honor the contracts (pre/postconditions) of their supertypes. Violations create subtle bugs where code works with the supertype but fails with a subtype.