an oop question

Chris Angelico rosuav at gmail.com
Fri Nov 4 11:26:53 EDT 2022


On Sat, 5 Nov 2022 at 02:21, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
>
> > ram at zedat.fu-berlin.de (Stefan Ram) writes [that Barbara Liskov said]:
> >
> >> |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.
>
> That seems overly restrictive, because it wouldn't allow S to
> override a method of T and make it do something different --
> which we do all the time in practice.
>
> >> Class contracts must hold for subclasses.
>
> That sounds like a much better way of saying it!
>

Yeah, I would agree with that latter definition. The trouble is that
few programs - and fewer programmers - really define which parts are
contracts, so it's much easier to say "a subclass behaves just like
the superclass(es) do(es)" - but it would be more accurate to qualify
that with "in the ways that the superclass(es) define as standard
behaviour".

ChrisA


More information about the Python-list mailing list