principles:liskov_substitution_principle
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
principles:liskov_substitution_principle [2018-05-27 18:40] – 2600:6c56:7a00:e45:0:7bb6:125a:4a85 | principles:liskov_substitution_principle [2021-09-02 14:18] – old revision restored (2021-09-02 10:26) 65.21.179.175 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Liskov Substitution Principle | + | ====== Liskov Substitution Principle ====== |
===== Variants and Alternative Names ===== | ===== Variants and Alternative Names ===== | ||
Line 6: | Line 6: | ||
===== Context ===== | ===== Context ===== | ||
/* fill in contexts here: */ | /* fill in contexts here: */ | ||
- | * [[contexts: | + | * [[contexts: |
- | * [[contexts: | + | |
===== Principle Statement ===== | ===== Principle Statement ===== | ||
- | |||
- | > " | ||
===== Description ===== | ===== Description ===== | ||
- | Object-oriented programming languages permit the derivation of subtypes from base types, and subtype polymorphism allows the passing of an object of a subtype where ever an object of the supertype is specified. Suppose '' | ||
- | The programming language does not enforce that the subtype behaves like the supertype. Method '' | + | ===== Rationale ===== |
- | |||
- | |||
- | ===== Rationale ===== | ||
- | |||
- | Let '' | ||
===== Strategies ===== | ===== Strategies ===== | ||
- | |||
- | * Only strengthen invariants in subclasses; never weaken them | ||
- | * Only weaken preconditions when overriding methods | ||
- | * Only strengthen postconditions when overriding methods | ||
- | * Use Delegation instead of Inheritance | ||
- | * Figure out better abstractions | ||
- | |||
- | ===== Caveats ===== | ||
- | |||
- | See section [[#contrary principles]]. | ||
===== Origin ===== | ===== Origin ===== | ||
- | |||
- | Barbara Liskov: // | ||
===== Evidence ===== | ===== Evidence ===== | ||
/* Comment out what is not applicable and explain the rest: */ | /* Comment out what is not applicable and explain the rest: */ | ||
- | + | /* | |
- | /* * [[wiki: | + | * [[wiki: |
- | + | * [[wiki: | |
- | * [[wiki: | + | * [[wiki: |
- | * [[wiki: | + | * [[wiki: |
- | + | */ | |
- | /* * [[wiki: | + | |
===== Relations to Other Principles ===== | ===== Relations to Other Principles ===== | ||
Line 63: | Line 41: | ||
==== Contrary Principles ==== | ==== Contrary Principles ==== | ||
- | * [[Keep It Simple Stupid]] | + | * [[principles:Keep It Simple Stupid]] |
==== Complementary Principles ==== | ==== Complementary Principles ==== | ||
- | * [[Model Principle]] (MP): MP demands inheritance relations to resemble an " | + | * [[principles: |
- | * [[Principle | + | * [[principles: |
==== Principle Collections ==== | ==== Principle Collections ==== | ||
Line 75: | Line 53: | ||
{{page> | {{page> | ||
- | + | ===== Example | |
- | ===== Examples | + | |
===== Description Status ===== | ===== Description Status ===== | ||
/* Choose one of the following and comment out the rest: */ | /* Choose one of the following and comment out the rest: */ | ||
- | /*[[wiki: | + | [[wiki: |
- | [[wiki: | + | /*[[wiki: |
/ | / | ||
- | |||
===== Further Reading ===== | ===== Further Reading ===== | ||
- | * Robert C. Martin: //Agile Software Development, | + | * Robert C. Martin: //Agile Software Development, |
* [[http:// | * [[http:// | ||
- | * [[wiki> | ||
- | * [[wp> | ||
- | * Barbara H. Liskov , Jeanette M. Wing: // | ||
- | * Barbara H. Liskov , Jeanette M. Wing: // | ||
- | |||
- | ===== Discussion ===== | ||
- | |||
- | Discuss this wiki article and the principle on the corresponding [[talk: |
principles/liskov_substitution_principle.txt · Last modified: 2021-10-18 21:50 by christian