multiple extensions to a class

Peter Otten __peter__ at web.de
Sat Jul 10 06:07:41 EDT 2004


Humpty Dumpty wrote:

> I.e.,  if I have a class A, and I want to add a block of functionality, I
> can derive it into a B that adds that fucntionality. If I want to add more
> functionality, I can derive B into a C. But if I want to add a third bit
> of functionality D directly to A, such that D knows nothing about B or C,
> I won't be able to instantiate an object that has all three extensions,
> namely an "ABCD". It will either be an "ABC" or an "AD".

This sounds like the following inheritance tree would be the obvious answer:

class A: pass
class B: pass
class C: pass
class D: pass

class AB(A, B): pass
class ABC(A, B, C): pass
class AD(A, D): pass

I may still be misunderstanding something...

Peter






More information about the Python-list mailing list