Python supports LSP, does it?
Terry Reedy
tjreedy at udel.edu
Thu Aug 11 15:02:08 EDT 2005
<en.karpachov at ospaz.ru> wrote in message
news:20050811105151.736450c8.jk at ospaz.ru...
> On Thu, 11 Aug 2005 01:19:19 +0100
> phil hunt wrote:
>
>> According to Wikipedia, the Liskov substitution principle is:
>>
>> 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
>>
>> To me, this is nonsense. Under this definition any subtype must
>> behave the same as its parent type, becausde if it doesn't there
>> will be some q(y) that are different to q(x).
>>
>> But if it behaves the same, what's the point of having a subtype?
>
> It does not behave the same, it has the same properties.
>
> In other words, if there is some true assertion about _any_ object of
> type
> x, then it's true about any object of type y, if y is derived from x.
>
> Quick-and-dirty example: any object of type "list" is iterable, and it is
> true
> as well for any object of some type derived from list.
I remember discussion of the LSP on comp.object some years ago when I was
reading it. (I presume there still are, just don't read it anymore.). One
of the problems is that biology and evolution do not obey it. Birds (in
general) can fly, but those in the ratite family, evolved later than order
aves, cannot. Nor can some birds in zoos after their wings have been
(un)fixed. In a quite literal sense, the 'fly' method got disabled.
The list goes on. In some cave-dwelling taxa, the 'see' method gets
genetically disabled. Bones breaks. Artifacts also get disabled by
accident or intention. So LSP conflicts with both scientific and everyday
classification.
Python lets one choose which hierarchy principle to adhere to.
Terry J. Reedy
More information about the Python-list
mailing list