Talk:Liskov substitution principle
From Wikipedia, the free encyclopedia
[edit] Incorrect citation of original paper
The article states that LSP was introduced in 1993 by Barbara Liskov and Jeanette Wing. However, the term was already in use by 1993, having been used by Jim Coplien in Advanced C++ Programming Styles and Idioms, the copyright date for which is 1992. The paper normally credited with advancing the principle is Barbara Liskov's "Data Abstraction and Hierarchy", which was published in 1988: http://citeseer.ist.psu.edu/context/93923/0 -- Kevlin 08:15, 29 August 2006 (UTC)
- I found a keynote speech with the same title from 1987 and changed the article intro to point to that. --P3d0 (talk) 15:29, 23 March 2008 (UTC)
[edit] Questionable Design by Contract inference
The article currently includes this:
- In general, the principle mandates that at all times objects from a class can be swapped with objects from an inheriting class, without the user noticing any other new behaviour. It has effects on the paradigms of design by contract, especially regarding to specification:
- postconditions for methods in the subclass should be more strict than those in the superclass
- preconditions for methods in the subclass should be less strict than those in the superclass
- no new exceptions should be introduced in the subclass
As much as I like Design by Contract, I don't think it's valid to infer anything about preconditions, postconditions, new exceptions, or "any other new behaviour" based on Liskov and Wing's original forumlation. That may be one interpretation or application of the Principle, but to claim that it is "mandated" by the Principle is an opinion that may not be shared by the bulk of practitioners in the field, and at the very least, should be accompanied by a reference. --P3d0 18:24, May 31, 2005 (UTC)
- You are very probably more knowledgeable than me about the topic (I'm following a reduced CS curriculum - one year). I have learned this from a theoretical Dutch 2nd bachelor-level textbook on OO, given by a prof enamoured of Design by Contract. My perspective on it is small. And mandating is a bit strong, yes. But isn't saying "mandating transparent swapping" just a more practical approach to the previous paragraph, i.e. this:
-
- 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).
- Feel free to put in perspective and change whatever you want:)--Phlebas 12:46, Jun 14, 2005 (UTC)
-
- Reflecting on it, perhaps the preconditions and postconditions are warranted. It's hard to imagine an interpretation of LSP that allows preconditions to be weakened in subclasses, for example. As for the rest, I'm still pondering that... --P3d0 14:12, Jun 14, 2005 (UTC)
[edit] comparison by strength
I just put up some changes - I found a little confusion in the "preconditions are weakened" vs "preconditions cannot strengthen" area: my formal logic background and some confusion in my undergrad students who referenced this article made me change it. I also added a bit about the functions using classes and the open/closed principle (slightly modified from foldoc.org[1], also repeated else where) since there were no articles with both bits of information together. Jgorman2 11:57, 3 June 2006 (UTC)
- One of my professors pointed out the concept of comparability was missing, so I tightened up the previous changes further and added a short bit on comparability. This can probably do with expansion if I have missed any cases of comparability. 202.7.166.163 06:15, 4 June 2006 (UTC)
-
- I don't understand the comparability thing. Clearly if predicate A is weaker than or equal to B, they are necessarily comparable. --P3d0 12:54, 4 June 2006 (UTC)
-
-
- In the normal case we have type T with precondition A and subtype S with precondtion A' same or weaker than A. In the incomparable case take T with conditions A and B and S with A' and B' where A' < A and B' > B. In this case the individual conditions can be compared for strength but not the whole condition. Does this make sense (it may not, it is late at night)? If it does, should it be added do you think? Jgorman2 14:18, 15 June 2006 (UTC)
-