replace the base class

aspineux aspineux at gmail.com
Wed May 30 16:40:41 EDT 2007


Hi

I would like a kind of function able to replace the base class like
that:

class Graph:
    pass

class Circle(Graph):
    pass

class Square(Graph):
    pass

class ColorGraph:
    pass

def Adopt(new_base_class, child_class, old_base_class):
    ....
    return newclass

ColorCircle=Adopt(ColorGraph, Circle, Graph)
ColorSquare=Adopt(ColorGraph, Square, Graph)


I have a lot of classes (Circle, Square, ...) that inherit all from
base class Graph
I have a more powerful class ColorGraph that do the same as Graph and
more.
I want to have new classes ColorCircle, ColorSquare that share exactly
the same code has
Circle or Square but inherit from base class ColorGraph to take
benefit the new features ?

How can I do that ?

I can get what I want by duplicating the source of all my child
classes,
and replace any occurrence of Graph by ColorGraph.
But when the code of Circle or Square is changed, I don't want to redo
the job.
I could also have a lot of new base class : 3DGraph, ......

Thanks

Alain




More information about the Python-list mailing list