I have multiple classes that have common functionality, which is implemented differently for various reasons. I'm using all these classes in the same context, but I don't know which one will be used until run time. I want to instantiate different classes, but use the same line of code to invoke the common functionality.
So, I've though of using inheritance (obviously), and now my code looks like this:
class Base():
def common(self):
return "abstract"
class A(Base):
def common(self):
return "A"
class B(Base):
def common(self):
return "B"
I want to be able to instantiate any of the derived classes as Base (so that I don't have to make a special case and checks for every new class I add) and call it's common method and get the desired "A" or "B" result.