# Liskov Substitution Principle

> A design rule that a subtype can replace its base type anywhere, because it keeps the base type's preconditions, postconditions and invariants.

Record: `architecture:liskov-substitution`
Kind: principle
Layer: [Structural Core](https://banes-lab.com/records/layer/structural-core.md)
Severity: mandatory
Scope: class, interface, type hierarchy
Aliases: LSP
Canonical: https://banes-lab.com/ontology#architecture-liskov-substitution

Listed in [Architecture principles](https://banes-lab.com/api/records/architecture.md), after [Open/Closed Principle (OCP)](https://banes-lab.com/records/architecture/open-closed.md) and before [Polymorphism](https://banes-lab.com/records/architecture/polymorphism.md).

## Repair

- Refactored by: Replace Inheritance, Extract Interface, Split Hierarchy
- Detected by: overridden method contract divergence
- Violated by: subclass weakening postconditions or strengthening preconditions
- Measured by: contract test pass rate across subtypes
- Enforced by: contract tests, type tests

## Requires

- [Contract Preservation](https://banes-lab.com/records/lexicon/contract-preservation.md)
- [Preconditions](https://banes-lab.com/records/architecture/preconditions.md)
- [Postconditions](https://banes-lab.com/records/architecture/postconditions.md)
- [Invariant](https://banes-lab.com/records/architecture/invariant.md)

## Reinforces

- [Polymorphism](https://banes-lab.com/records/architecture/polymorphism.md)
- [Type Safety](https://banes-lab.com/records/architecture/type-safety.md)

## Enables

- [Safe Substitution](https://banes-lab.com/records/lexicon/safe-substitution.md)
- [Substitutability](https://banes-lab.com/records/lexicon/substitutability.md)

## Conflicts with

- [Broken Inheritance](https://banes-lab.com/records/lexicon/broken-inheritance.md)
- [Broken Inheritance](https://banes-lab.com/records/lexicon/broken-inheritance.md)

## In tension with

- [Narrow Specialized Behavior](https://banes-lab.com/records/lexicon/narrow-specialized-behavior.md)

## Tensions

- [Liskov Substitution Principle (LSP) / Narrow Specialized Behavior](https://banes-lab.com/records/tension/liskov-substitution-principle-lsp-narrow-specialized-behavior.md)

## Severity

- [mandatory](https://banes-lab.com/records/vocabulary/severity-mandatory.md)

## Category

- [SOLID / Object-Oriented Design](https://banes-lab.com/records/architecture-category/solid-object-oriented-design.md)

## Enabled by

- [Design by Contract](https://banes-lab.com/records/architecture/design-by-contract.md)

## Linked from

- [The structural domain](https://banes-lab.com/software-architecture/principles/the-structural-domain.md)
- [Contracts / Interfaces / Compatibility](https://banes-lab.com/ontology/principles/architecture-category-contracts-interfaces-compatibility.md)
- [SOLID / Object-Oriented Design](https://banes-lab.com/ontology/principles/architecture-category-solid-object-oriented-design.md)
- [Schema / Canonical Data / Semantics](https://banes-lab.com/ontology/principles/architecture-category-schema-canonical-data-semantics.md)
- [Core Vocabulary](https://banes-lab.com/ontology/lexicon/lexicon-category-core-vocabulary.md)
- [Quality Attributes](https://banes-lab.com/ontology/lexicon/lexicon-category-quality-attributes.md)
- [SOLID / Object-Oriented Design](https://banes-lab.com/ontology/lexicon/lexicon-category-solid-object-oriented-design.md)
- [Severity levels](https://banes-lab.com/ontology/schema/the-vocabulary-severity.md)
- [The resolutions](https://banes-lab.com/ontology/schema/the-resolutions.md)
