About the use of **args

John Roth newsgroups at jhrothjr.com
Wed Dec 10 07:48:38 EST 2003


"Zunbeltz Izaola" <zunbeltz at wm.lc.ehu.es.XXX> wrote in message
news:m1oeuhqd7k.fsf at lcpxdf.wm.lc.ehu.es...
>
> Hi
>
> I'm starting a new proyect and i'm in doubt about diferent interfaces
> for my clases. My clases will have a lot of attributes and i'm want to
> know what aproach could be the best
>
> 1) Define one SetAttribute/GetAttribute pair of method for each
>    attribute.
> 2) Define one SetAttribute/GetAttribute which argument is a key=value
>    format.
>
> Any advaice?
>
> Thanks in advance
>
> Zunbeltz Izaola

I presume  you're talking about constructing the object,
not about state changes after it's been constructed and
released into the wild?

In that case, the "best" pattern is to never let the object
appear half constructed. There are a wide variety of ways
of doing this, from passing all the needed parameters into
the constructor, to numerous variations on the factory
pattern. And I wouldn't be adverse to the other responder's
practice of simply plugging values into the instance while
it's still in the factory: most real world objects don't contain
the logic for their construction, so why should our programming
objects?

John Roth
>






More information about the Python-list mailing list