B
BrJohan
Assume having this class hierarchy: (in principle and without details)
class A(object):
class B1(A):
class B2(A):
class C1(A1):
class C2(A1):
class C3(B1):
class C4(B2):
each of those classes have an initializer __init__(self, data): and an
overloaded __new__(cls, data):
is it then possible to have this call:
obj = A(data)
return an instance of that particular class (e.g. class C3) in the
hierarchy that - as decided by the __new__ functions - is the 'correct' one?
A.__new__ could select between A, B1 and B2, while B1.__new__ could choose
from B1, C3 and C4.
I know how to use a class factory - and could work around using such a
mechanism. However I am interested to know if I could let the classes do the
work by themselves.
/BJ
class A(object):
class B1(A):
class B2(A):
class C1(A1):
class C2(A1):
class C3(B1):
class C4(B2):
each of those classes have an initializer __init__(self, data): and an
overloaded __new__(cls, data):
is it then possible to have this call:
obj = A(data)
return an instance of that particular class (e.g. class C3) in the
hierarchy that - as decided by the __new__ functions - is the 'correct' one?
A.__new__ could select between A, B1 and B2, while B1.__new__ could choose
from B1, C3 and C4.
I know how to use a class factory - and could work around using such a
mechanism. However I am interested to know if I could let the classes do the
work by themselves.
/BJ