Liskov, Barbara ; Wing, Jeannette July Substitutability is a principle abstrsction object-oriented programming stating that, in a computer programif S is a subtype of T, then objects of type T may be replaced with objects of type S i. From Wikipedia, the free encyclopedia. In addition to the signature requirements, the subtype must meet a number of behavioural conditions. This paper discusses LSP in the mentioned context.
|Published (Last):||9 May 2012|
|PDF File Size:||1.65 Mb|
|ePub File Size:||11.60 Mb|
|Price:||Free* [*Free Regsitration Required]|
Behavioural subtyping is a stronger notion than typical subtyping of functions defined in type theory , which relies only on the contravariance of argument types and covariance of the return type. Behavioural subtyping is undecidable in general: if q is the property "method for x always terminates ", then it is impossible for a program e. Nonetheless, the principle is useful in reasoning about the design of class hierarchies. Covariance of return types in the subtype.
No new exceptions should be thrown by methods of the subtype, except where those exceptions are themselves subtypes of exceptions thrown by the methods of the supertype. In addition to the signature requirements, the subtype must meet a number of behavioural conditions.
These are detailed in a terminology resembling that of design by contract methodology, leading to some restrictions on how contracts can interact with inheritance : Preconditions cannot be strengthened in a subtype. Postconditions cannot be weakened in a subtype.
Invariants of the supertype must be preserved in a subtype. History constraint the "history rule". Objects are regarded as being modifiable only through their methods encapsulation. Because subtypes may introduce methods that are not present in the supertype, the introduction of these methods may allow state changes in the subtype that are not permissible in the supertype. The history constraint prohibits this. It was the novel element introduced by Liskov and Wing.
A violation of this constraint can be exemplified by defining a mutable point as a subtype of an immutable point. This is a violation of the history constraint, because in the history of the immutable point, the state is always the same after creation, so it cannot include the history of a mutable point in general. Fields added to the subtype may however be safely modified because they are not observable through the supertype methods. Thus, one can derive a circle with fixed center but mutable radius from immutable point without violating LSP.
Origins[ edit ] The rules on pre- and postconditions are identical to those introduced by Bertrand Meyer in his book Object-Oriented Software Construction. Both Meyer, and later Pierre America, who was the first to use the term behavioral subtyping, gave proof-theoretic definitions of some behavioral subtyping notions, but their definitions did not take into account aliasing that may occur in programming languages that support references or pointers.
Taking aliasing into account was the major improvement made by Liskov and Wing , and a key ingredient is the history constraint.
Zasada podstawienia Liskov
BARBARA LISKOV DATA ABSTRACTION AND HIERARCHY PDF
(요약) Data Abstraction and Hierarchy by Barbara Liskov 1988
Data Abstraction and Hierarchy--Barbara Liskov