Liskov substitution and inheritance
Gene Bushuyev wrote:
Going back to the classic work of Barbara Liskov, where she defined the
"What is wanted here is something like the following substitution property: If
for each object o1 of type S there is an object o2 of type T such that for all
programs P defined in terms of T, the behavior of P is unchanged when o1 is
substituted for o2 then S is a subtype of T."
The kind of polymorphism that you're discussing I've always called
'inclusional polymorphism', meaning that a type S 'includes' the type T
(using Liskov's terms).
What Liskov describes though sounds tighter as she specifies that the
behaviour of P is unchanged. It seems to me that a reasonable
interpretation of 'unchanged behaviour' would not include the
difference in bahaviour wrought by overriden virtual methods.
What it does cover though is the sort of substitution that you get when
you use a 'long' for an 'int', i.e. 'operational polymorphism' where
you expect different types to provide the same operations with the same
results. This is what you get with templated functions (the program P),
I've come across 'Liskov substitution' as a term a few times, but I've
not come across a good definition of it with examples of how the term
should be applied.
Can you shed some further light on it?
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]