In object-oriented programming, the Liskov substitution principle is a particular definition of subtype that was introduced by Barbara Liskov and Jeannette Wing in a 1993 paper entitled Family Values: A Behavioral Notion of Subtyping. (It is not the only definition; see datatype.)
The principle was formulated succinctly in a subsequent paper as follows:
Thus, Liskov and Wing's notion of "subtype" is based on the notion of substitutability; that is, if S is a subtype of T, then objects of type T in a program may be replaced with objects of type S without altering any of the desirable properties of that program (e.g., correctness).
A function using a class hierarchy violating the principle uses a reference to a base class but must know about all the derivatives of that base class. Such a function violates the open/closed principle because it must be modified whenever a new derivative of the base class is created.
In the design by contract methodology, the principle leads to some restrictions on how contracts can interact with inheritance:
In addition, these conditions must be comparable. The conditions and are not comparable with the conditions and as one set of conditions does not wholly subsume the other. Classes with incomparable pre- or postconditions are not substitutable under the principle.
In addition, the principle implies that no new exceptions should be thrown by methods of the subclass, except where those exceptions are themselves subtypes of exceptions thrown by the methods of the superclass. See covariance and contravariance.
Object-oriented programming | Type theory
Liskovsches Substitutionsprinzip | Principio di sostituzione di Liskov
This article is licensed under the GNU Free Documentation License.
It uses material from the
"Liskov substitution principle".
Home Page • arts • business • computers • games • health • hospitals • home • kids & teens • news • physicians • recreation• reference • regional • science • shopping • society • sports • world