Copy construction of class instance object

Steven Taschuk staschuk at telusplanet.net
Thu May 29 11:47:55 EDT 2003


Quoth Bror Johansson:
  [...]
> One of my ideas was to have class super recognize the common header and
> defining classes subx to take an instance of super as argument to __init__
> and 'copy' the header info before reading rest of file.

(Btw, 'super' is an unfortunate name for a class; there's a
built-in of that name.  I know the name was just for explanation,
but still.)

> After having considered follow up comments to my first posting, and thinking
> a little more, I have given up my original thoughts. Another - and simpler -
> design will be chosen.

It does seem more straightforward to have separate factories.

It's possible you could do the superclass/subclass magic with
sufficiently clever implementations of __new__; the idea would be
that you'd call supercls(data) and actually get an instance of a
specific subclass of supercls, as appropriate to the data.  But
I'm not sure exactly how this might be done.

-- 
Steven Taschuk             "[W]e must be very careful when we give advice
staschuk at telusplanet.net    to younger people: sometimes they follow it!"
                             -- "The Humble Programmer", Edsger Dijkstra





More information about the Python-list mailing list