Python supports LSP, does it?

Gregory Bond gnb at itga.com.au
Wed Aug 10 23:49:17 EDT 2005


phil hunt wrote:

> 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).

Not necessarily..... the set of operations on y could be a superset of 
the set of operations on x.  So you could have q(y) == q(x) (for all q 
applicable to x) but there could be w(y) that has no w(x).  In C++ 
terms, this implies no virtual functions.

Which is not to say that I'm disagreeing with your basic point: 
insisting on q(y) == q(x) for all q will greatly limit your use of 
polymorphism, unless you are 'sensible' (or perhaps what a mathematician 
would call 'loose') about how you define your "q"s!



More information about the Python-list mailing list