Variable inheritance

Roman Suzi rnd at onego.ru
Tue May 22 04:23:43 EDT 2001


On Tue, 22 May 2001, Oleg Broytmann wrote:

> On Tue, 22 May 2001, Roman Suzi wrote:
> > Can anyone provide an example where MI is used for right purpose,
> > not just to quickly hack something?
> 
>    Easy. Think you are working with object of some classes. Let say there
> are Animals and ColorThings. Imagine us constructing Animals hierarchy:
> 
> class Animal: ...
> 
> class Mouse(Animal): ...
> 
> class Elephant(Animal): ...
> 
>    Now to color things:
> 
> class ColorThings:
>    color = "no color"
> 
> class Red(ColorThings):
>    color = "red"
> 
> class Grey(ColorThings):
>    color = "grey"
> 
>    Now let us construct grey mouse:
> 
> class GreyMouse(Grey, Mouse): pass
> 
>    What about red elephant? :)

This is indeed a contra-example and is a bad design, because
it leeds to combinatorically bloated code, in which you need
M*N*K... classes to have all kinds of objects.

This example is also artificial, because in reality we do
not have so orthogonal properties. What if you will need
to specify types of texture and their colors, etc.
Will you end with:

class WhiteStripBlackZebra(WhiteStripeThing, Black, Zebra...)

???

No, this must be done differently, without combinatorial explosion of
classes.

I was always very irritated when somebody proposed something like

class Line(Point):
  ...

just because line could be made of two points.

class Rect(Point, Dimensions):

is no better.



> Oleg.
> ----

Sincerely yours, Roman A.Suzi
-- 
 - Petrozavodsk - Karelia - Russia - mailto:rnd at onego.ru -
 





More information about the Python-list mailing list