Liskov substitution principle

Liskov substitution principle

In object-oriented programming, the Liskov substitution principle is a particular definition of "subtype" that was introduced by Barbara Liskov in a 1987 conference keynote address entitled "Data abstraction and hierarchy"] as follows:

:"Let q(x) be a property provable about objects x of type T. Then q(y) should be true for objects y of type S where S is a subtype of T."

Thus, Liskov'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).

Design by contract

The Liskov substitution principle is closely related to the design by contract methodology, leading to some restrictions on how contracts can interact with inheritance:

*Preconditions cannot be strengthened in a subclass.
*Postconditions cannot be weakened in a subclass.

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.

A function using a class hierarchy violating the principle uses a reference to a base class, yet must have knowledge of the subclasses. Such a function violates the open/closed principle because it must be modified whenever a new derivative of the base class is created.

References


Wikimedia Foundation. 2010.

Игры ⚽ Нужно сделать НИР?

Look at other dictionaries:

  • Barbara Liskov — (born Barbara Jane Huberman, 1939) is a computer scientist. She is currently the Ford Professor of Engineering in the Electrical Engineering and Computer Science department and an Institute Professor at the Massachusetts Institute of Technology.… …   Wikipedia

  • S.O.L.I.D. — S.O.L.I.D. Sommaire 1 Qu est ce que S.O.L.I.D …   Wikipédia en Français

  • Принцип подстановки Барбары Лисков — (англ. Liskov Substitution Principle, LSP) в объектно ориентированном программировании является специфичным определением подтипа предложенным Барбарой Лисков в 1987 году на конференции в основном докладе под названием Абстракция данных и… …   Википедия

  • Принцип подстановки Лисков — Принцип подстановки Барбары Лисков (англ. Liskov Substitution Principle, LSP) в объектно ориентированном программировании является специфичным определением подтипа предложенным Барбарой Лисков в 1987 году на конференции в основном докладе… …   Википедия

  • Circle-ellipse problem — The circle ellipse problem in software development (sometimes known as the square rectangle problem) illustrates a number of pitfalls which can arise when using subtype polymorphism in object modelling. The issues are most commonly encountered… …   Wikipedia

  • SOLID (объектно-ориентированное программирование) — У этого термина существуют и другие значения, см. Solid. SOLID это аббревиатура пяти основных принципов дизайна классов в объектно ориентированном проектировании  Single responsibility, Open closed, Liskov substitution, Interface segregation …   Википедия

  • Jeannette Wing — Jeannette M. Wing is a computer science professor at Carnegie Mellon University, Pittsburgh, United States.Wing has been a leading member of the formal methods community, especially in the area of Larch. She has led many research projects and has …   Wikipedia

  • Women in computing — Global concerns about current and future roles of women in computing occupations gained more importance with the emerging information age. These concerns motivated public policy debates addressing gender equality as computer applications exerted… …   Wikipedia

  • Solid (disambiguation) — Solid most commonly refers to a phase (or state) of matter.Solid may also refer to:*Solid geometry, the traditional name for the geometry of three dimensional Euclidean space **Polyhedron, a geometric object with flat faces and straight edges *A… …   Wikipedia

  • List of object-oriented programming terms — Those words found in object oriented programming. Some are related to OOP and some not. A * Abstract class (also called deferred class) * Abstract method * Abstraction (computer science) * Access control * Accessor method * Allocated class *… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”