I have read the other questions related to this issue, but none of them seemed to provide a proper general answer and hence I am posting this question.
Assume I have to following code:
class A():
def do(x:int):
print(x)
class B():
def do(y:str, z:List[int]):
print(y)
print(z)
class C():
def do(x:int, y:str):
print(x)
print(y)
def my_factory(name)
if name=="a":
return A()
elif name=="b":
return B()
elif name=="c":
return C()
class my_class():
def __init__(self, config):
self.child = my_factory(config)
def jo(x, y, z, a, b, c):
self.child.do(???)
# other stuff
As you can see, my code implements a factory pattern but each of the potential factory objects has unique signature. I wonder which pattern is suited for this case and how it is called. My current idea is something like this:
@dataclass
class factory_object_input:
x:int
y:str
z:List[int]
class A():
def do(i:factory_object_input):
print(i.x)
#classes B and C accordingly.
class my_class():
def __init__(self, config):
self.child = my_factory(config)
def jo(x, y, z, a, b, c):
i = factory_object_input(x,y,z)
self.child.do(i)
# other stuff
Is that the way to go or do I violate the factory pattern with that?