Inheritance question
Alex Martelli
aleaxit at yahoo.com
Mon Sep 20 15:08:11 EDT 2004
Yannick Turgeon <nobody at nowhere.com> wrote:
...
> Say "0144AYHR78" (encoded data) means "Add client Joe" and "0589UAWERT"
> means "Ship 3 compressors to Joe". What I want to do is to create a "A"
> instance which find the command type and parameters and "mutate" itself to
> the good command. All command parameters ("Joe" for the first one and
...
> Any suggestion to do this in a better way
Yeah -- Peter Otten explained in more detail, but summing up: what you
need is a Factory Design Pattern -- a function that takes the encoded
data, decodes it, instantiates the appropriate class (probably based on
a dict to map code->class) with the appropriate parameters. No reason
whatsoever to have an instance mutate its own class in this case.
Alex
More information about the Python-list
mailing list