design question
Gonçalo Rodrigues
op73418 at mail.telepac.pt
Thu Sep 26 11:58:44 EDT 2002
Hi,
My problem is the following: I have a module to which I want to build a
more useful interface. An example would be a third-party extension
module where many of the classes are begging to be dressed in Python's
specific protocols (as sequences, mappings, etc.).
To make matters even more concrete, suppose that among the classes to be
wrapped we have
Class1
|
|
Class2
Where the dashed line means a parent-child relationship. Now what I want
is something like
Wrapper1
|
|
Wrapper2
where Wrapper1 (Wrapper2) wraps Class1(Class2) and the inheritance
reltionships between the several wrappers mirror those of the classes
they wrap -- but as I said, the protocol that the wrappers have can be
substantially different from the classes they wrap.
Leaving aside the question of the usefulness of doing all this, I would
like to ask how would you proceed? Making Wrapper derive from Class is
stupid since their protocols can differ widely and I would end up with
lots of diamonds in the inheritance graph. On the other hand I could
just do:
class Wrapper1(object)
def __init__(self, <more args>):
self.__wrap = Class1()
<more initialization code>
But then if I did the same with Wrapper2, it would be at least quirky
since it inherits from Wrapper1 but it wraps Class1 <scratches head in
puzzled bewilderment>
I know I am being a little vague in my question, but does anyone have
any ideas? Open-source code where this "same problem" has been tackled?
With my best regards,
Gonçalo Rodrigues
More information about the Python-list
mailing list