multiple inheritance of a dynamic list of classes?

massimo s. devicerandom at gmail.com
Tue Feb 13 11:02:24 EST 2007


On 13 Feb, 12:46, Peter Otten <__pete... at web.de> wrote:
> Well, what problems ocurring with
>
> class A: pass
> class B: pass
> class C(A, B): pass
>
> could be avoided by writing
>
> class A: pass
> class B(A): pass
> class C(B): pass
>
> instead? Classes have to be designed for subclassing, so essentially you get
> two interfaces, one for subclasses and one for client code instead of just
> the latter. A more relevant mantra governing inheritance is "Flat is better
> than nested".

I am truly getting lost. Are you saying that doing A-->B(A)--C(B) is
better than C(A,B)? And isn't the former thing nested? Or are you
saying that C(A,B) is better than A,B(A),C(B)? And in both cases:why?

And why "classes have to be designed for subclassing"? I often do
classes that are not thought to be subclassed.

> If you use attributes starting with two underscores inside a method, Python
> transparently prepends them with the class name. This allows to you to use
> the same variable name in two base classes and reduces coupling:

Wow, I didn't know it. Thanks a lot.

> But if two classes with the same name use the "private" variable, the
> mechanism fails:

Of course.I'll remember it.

m.




More information about the Python-list mailing list