Re: Does this behavior have a better design pattern?

2018-11-08 Thread Peter Otten
Grant Edwards wrote: > On 2018-11-07, Peter Otten <__pete...@web.de> wrote: >> lampahome wrote: >> >>> Above is I thought to make code clear, and this pattern is called simple >>> factory? > > [...] > >>> *Is there better design pattern for me?* > >> Generally speaking you get better solutions

Re: Does this behavior have a better design pattern?

2018-11-08 Thread Grant Edwards
On 2018-11-07, Peter Otten <__pete...@web.de> wrote: > lampahome wrote: > >> Above is I thought to make code clear, and this pattern is called simple >> factory? [...] >> *Is there better design pattern for me?* > Generally speaking you get better solutions when you ask yourself > "How can

Re: Does this behavior have a better design pattern?

2018-11-07 Thread lampahome
> > > The rest is just cruft ;) > > > > *Is there better design pattern for me?* > > If A does B to C, is that a crime? > No > Your problem description suffers from overgeneralisation. > > Generally speaking you get better solutions when you ask yourself > "How can I solve this problem

Re: Does this behavior have a better design pattern?

2018-11-07 Thread Peter Otten
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

Does this behavior have a better design pattern?

2018-11-07 Thread lampahome
I have two categories A,B, and A has 2 items A1,A2 B have 2 items B1, B2. I have two class A and B, and A will handle A1,A2, B handle B1,B2. I want to parse one of A1,A2,B1,B2 to script and generate the corresponding class(object). Ex: Both in class A and B, all have func1(), func2(). What I