[Python-Dev] Single- vs. Multi-pass iterability
Alex Martelli
aleax@aleax.it
Mon, 15 Jul 2002 21:12:54 +0200
On Monday 15 July 2002 04:19 pm, Barry A. Warsaw wrote:
> >>>>> "AM" == Alex Martelli <aleax@aleax.it> writes:
>
> AM> The big question is rather: given that Isub inherits from
> AM> Isuper, does any object implementing Isub also implicitly
> AM> implement Isuper?
>
> There's another issue that Jim Fulton likes to bring up, IIRC. If
> class Super implements IInterface, does class Sub(Super) also
> (automatically) implement IInterface?
>
> I could be totally misremembering, but I believe that Jim would say
> "no". Class Sub would have to explicitly declare that it also
> implements IInterface.
I fully agree with Jim. Inheritance is often the handiest way to
_implement_ some things, but not if it comes with a mandatory
contract that you have to respect (specifically, supplying some
interfaces because your superclasses supply them).
In C++, you distinguish by using private inheritance when you
are inheriting just to get implementation, public inheritance to
signify that you're also accepting the IS-A obligations (and then
it gets messy because private affects accessibility and not
visibility, but that's C++'s specific problem:-).
I _like_ to use inheritance of implementation exactly for that --
implementation purposes -- without mystical IS-A obligations.
It _may_ be because most of my experience is with COM, which
does not expose implementation inheritance and gives each
object full control on what interfaces it wants to supply -- behind
the scenes, the object's implementation is free to use inheritance,
delegation, or, as far as COM's concerned, bat wings and newt
blood -- that's the object's business. But I do have enough
experience in bare (no-COM) C++ and Java to know that I
found the COM approach distinctly preferable (at least when the
tools offered easy ways to get typical behavior while still leaving
enough hooks and handles for me to get fine-grained control
when needed -- Microsoft's ATL library was quite good for that).
Alex