0

We are using an external python library (e.g. Lib1) which have couple of classes (e.g. Class A, Class B). We want to create a wrapper component on top of that library so that in future if we want to replace that library with some other library, our application does not need to change the code. For initial implementation of this component, we are fine with creating this component with same Classes and methods as in Lib 1.

If Class A have method m1 and m2 and Class B have method m3 and m4, and m3 and m4 take Class A instance as parameter; We do not want to end up with Class Wrapped_A with its method m1 and m2 and Class Wrapped_B with its method m3 and m4.

Is there any way to implement a generic proxy/delegate object or class so that we do not have to wrap every methods in Wrapped_A and Wrapped_B but still our application can call def m1, m2, m3 and m4 on them (also, still an object of Class A being passed to m3 and m4).

I am new to python, tried to understand decorator and metaprogramming but that did not helped. Also, our requirement currently is not to add any new logic in class or their methods but just to create proxy object/methods which will just delegate the calls to external library objects/methods.

Thanks for the help !

Jaat
  • 1
  • 1
  • Why don't you want Wrapped_A and Wrapped_B to have m1/m2 and m3/m4, if they are to wrap/mimic the origin A and B? –  Jan 28 '16 at 06:47
  • Currently, it sounds like you just want to inherit from A and B. And since they are in a different module (that is, namedspaced), you can call the wrappers A and B as well. So that `from original import A` gives you the original A, while `from wrapper import A` gives you the wrapped A. –  Jan 28 '16 at 06:49
  • You'll need to be more concrete though; this is too vague. –  Jan 28 '16 at 06:49
  • Hi, welcome to StackExchange! This kind of looks like homework, we can help, but we'd like to see a good faith attempt to solve the problem yourself first, or you ask about specific problems with your existing implementation. If you can't do that yet, try some more of your own work first or searching for more general help; your professor is likely to be a better resource at this stage than Stack Overflow. – Tim Jan 28 '16 at 06:53

0 Answers0