I've been exposed to python for about 2 years and I have never used or come across a wrapper class until today when I see something like this:
class Wrapper(object):
def list_to_str(self, my_list):
if self.mode == 'convert':
return str(my_list)
def get_tree(self, my_list)
my_tree = self.list_to_tree(my_tree)
return my_tree
class RealClass(Wrapper):
def __init__(self, mode):
self.mode = mode
def list_to_tree(self, list):
""convert list to tree""
return tree
I was quite annoyed by this code and personally find it really ugly.
However, because I have not been exposed to wrapper class in production environment (or any other environment) I'm not sure if the above practice is find.
Please tell me if the ^ is OK, and if not, please tell me how should I re-factor these 2 classes (completely remove wrapper?) or provide me some resources.
So far I looked at the python documentation and some other posts related to the wrapper class, but it seems that all the _ getattribute _ and stuff like that doesn't really apply here.
Wrapperis not an actual wrapper in your case. It is a parent class toRealClass. This, you probably only createRealClassinstances which inherit some of their behavior from theWrapperclass.