Currently, I have a @classmethod that returns the right class given a variable. It looks something like:
class Parent():
@classmethod
def GetInstance(cls, variable):
if variable == 'foo':
return Child()
class Child(Parent):
def Something(self):
pass
instance = Parent.GetInstance('foo')
result = instance.Something()
I prefer not to define and use GetInstance. Instead, I would like the Main() to simply be:
instance = Parent('foo')
result = instance.Something()
While keeping all the benefits of the structure above. I want class Parent() to return an object of class Child() when called, without the need of using a method. __init__ unfortunately does not seem to help, as it cannot return anything. Any ideas?