I have two classes which extend two different base classes. Those classes setup custom environment.
The are three methods common in both the classes: prepare(), setup() and teardown().
Each method overrides base class method. (Also they have super() calls.) Also ExtendedBase extends Base.
First class:
ClassA(Base):
def __init__(self, args):
super().__init__(args)
self._private = OtherClass()
def prepare(self, args):
super().prepare(args)
self._private.prepare()
def setup(self, args):
super().setup(args)
self._private.setup(self._smth, args)
def teardown(self):
self._private.teardown()
super().teardown()
Second class:
ClassB(ExtendedBase):
def __init__(self, args):
super().__init__(args)
self._private = OtherClass()
def prepare(self, args):
super().prepare(args)
self._private.prepare()
def setup(self, args):
super().setup(args)
self._private.setup(self._smth, args)
def teardown(self):
self._private.teardown()
super().teardown()
Is this a way to avoid duplicate methods?
I thought about multiple inheritance with the Environment class which will contain duplicated methods, but am puzzled about how to implement this and if it is a good idea at all.
Edited: Unfortunately I couldn't do anything with classes hierarchy. ClassA and ClassB should inherit corresponding classes and override or use the parent's method.