multiple extensions to a class

Jeff Shannon jeff at ccvcorp.com
Fri Jul 9 13:28:33 EDT 2004


Humpty Dumpty wrote:

>One possibility would be to define the extensions B,C and D as functions and
>add those functions to A with new.instancemethod. Any other ideas on how to
>do this? E.g. is it possible to *add* base classes to a class? I could add
>the extensions by adding them as base classes to A.
>  
>

You might consider making class A into a container of some sort -- i.e., 
give it someplace to store a list of "decorator" objects, and then make 
B, C, and D into such decorators (rather than subclasses of A).  You'll 
have to arrange some way of dispatching messages to A that are intended 
for the decorators, and possibly some way for the decorators to talk to 
each other.  (It's hard to say whether you'd be better off making B and 
C separate decorators, or whether to subclass C from B -- depends on 
your specific application.)

Jeff Shannon
Technician/Programmer
Credit International




More information about the Python-list mailing list