Factory pattern implementation in Python
Terry Reedy
tjreedy at udel.edu
Mon Dec 4 18:13:42 EST 2006
<bearophileHUGS at lycos.com> wrote in message
news:1165263327.407166.276160 at l12g2000cwl.googlegroups.com...
> Dennis Lee Bieber:
>> Presuming the <event x> is a type code I'd just set up a list of
>> functions:
>> Then create a dictionary of them, keyed by the <event x> code
>> processors = { "1" : process_1,
>> "2" : process_2,
>> ....
>> "x" : process_x }
>
> Just a dict of functions was my solution too, I think avoiding more
> complex solutions is positive.
If the event codes start at 0 and run sequentially, a tuple or list would
be even easier.
More information about the Python-list
mailing list