Does this behavior have a better design pattern?
Peter Otten
__peter__ at web.de
Wed Nov 7 06:00:14 EST 2018
lampahome wrote:
> Above is I thought to make code clear, and this pattern is called simple
> factory?
This is a factory function:
> def get_class(obj):
> if obj == 'A1' or obj == 'A2':
> return A(obj)
> else:
> return B(obj)
The rest is just cruft ;)
>
> *Is there better design pattern for me?*
If A does B to C, is that a crime?
Your problem description suffers from overgeneralisation.
Generally speaking you get better solutions when you ask yourself
"How can I solve this problem efficiently?"
rather than
"What fancy design patterns can I use while solving this problem?"
More information about the Python-list
mailing list