PEP 245: Python interfaces

Alex Martelli aleaxit at yahoo.com
Thu Mar 29 15:00:43 CEST 2001


"Martin von Loewis" <loewis at informatik.hu-berlin.de> wrote in message
news:j4wv99m503.fsf at informatik.hu-berlin.de...
> Michel Pelletier <michel at digicool.com> writes:
>
> > Because that expression list defines inheritance, and interfaces are not
> > inherited.
>
> That depends on your viewpoint. I'd, it defines subtyping, i.e. an
> is-a relationship. An object implementing foo certainly is-a foo.

But is-a is not what inheritance currently asserts in Python: one
may perfectly well inherit for purely 'implementation' purposes, with
no need whatsoever to keep Liskov substitutability (one may inherit
to use methods A, B and C, while overriding method D with a version
that requires more from its arguments -- just for example!).

In C++, one distinguishes "is-a" inheritance from 'just-implementation'
inheritance by having the first kind public, the second kind private.

Fortunately, Python eschews such subtleties (which breed their own
complications); adopting the explicit and very clear distinction that
Java draws between 'extending' (a class) and 'implementing' (an interface)
seems much preferable to me than either totally blurring (in the Python
source) this crucial distinction, or adopting C++-inspired half-remedies
to the is-a/vs/implementation confusion.


Alex






More information about the Python-list mailing list