Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2003-03-25 12:19:43


Christoph Kögl <christoph_at_[hidden]> writes:

> You might want to read
> http://www.objectmentor.com/resources/articles/lsp.pdf for
> a rationale of the LSP.

It says:

    FUNCTIONS THAT USE POINTERS OR REFERENCES TO BASE CLASSES MUST BE ABLE
    TO USE OBJECTS OF DERIVED CLASSES WITHOUT KNOWING IT .

    The above is a paraphrase of the Liskov Substitution Principle
    (LSP). Barbara Liskov first wrote it as follows nearly 8 years ago

    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 problem is that if the top statement allows overriding virtual
functions in derived classes with different behavior, then it says
something very different from the bottom one (the actual LSP).

> A somewhat different view is expressed in
> http://alistair.cockburn.us/crystal/articles/cdos/constructivedesconstructionofsubtyping.htm.

That discussion leaves a lot more room for correct interpretations, by
presenting lots of different viewpoints. I like that one.

I was just saying that the LSP doesn't really apply well to common
well-founded C++ software engineering practices, so arguments based on
the LSP don't hold much water with me. Note that it also seems to
fail to cover abstract base classes (which don't have a behavior in
and of themselves).

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk