Variable inheritance

Alex Martelli aleaxit at yahoo.com
Wed May 23 04:20:21 EDT 2001


"Roman Suzi" <rnd at onego.ru> writes:
    ...
> > "Flying Creature" vs "Swimming Creature" vs "Walking Creature"...
> > many creatures have multiple ways of locomotion.  Air-Breather
> > vs Water-Breather... ever heard of amphibians?-)
> 
> Yes! 
> 
> But Python allows to add properties independently of 
> inheritance. Some time ago I posted an example for 
> constructing above mentioned creatures without 
> any inheritance.

Yes, AND?  *WHAT* is the advantage of re-doing the
same mechanisms of look-up, overriding, &c, that 
Python freely offers you in its built-in inheritance
infrastructure?!


> Properties could be used on their own, without 
> complications of inheritance! (which sometimes
> inherits more than needed).

What "complications of inheritance"?!  We're
talking *PYTHON*, you know, not C++ -- no issues
of virtual bases vs repeated bases, etc, etc.
Everything is crystal-clear.

A typical mixin class, intended to be multiply
inherited from and support an application of
what the Go4 call the "template Design Pattern",
exposes a minimal consistent set of higher level
('template') methods that correctly sequence the
strategy of calls to lower level ('atomic')
methods on self -- just for example.  

One just multiply inherits from it, overrides 
those atomic methods one needs to override 
(including ones that raise NotImplementedError 
to FORCE override), and now one is exposing the 
higher level methods to client code, quite 
effectively from all POVs. Everything as smooth 
and possible as could possibly be.

Recoding this excellent design in terms of
aggregation and delegation mires you in a maze
of little niggling complexities on either or
both sides of the client and supplier of the
'correctly sequence strategy of calls' kind
of functionality.  Lots of busywork and lots
of boilerplate coding -- and all *FOR WHAT*?!

*WHAT BENEFITS DO YOU CLAIM FOR ALL OF THIS
BUSYWORK YOU WOULD INFLICT ON PROGRAMMERS*?!
And how do you prove those benefits with such
certainty that you dare tell everbody else,
happily using Python's excellent MI to good
effect for such purposes, that their designs
are *BAD*?!


Alex






More information about the Python-list mailing list