Is there a way to instantiate a subclass from a class constructor?

Paul Rubin phr-n2001 at nightsong.com
Sun Sep 23 04:43:39 EDT 2001


"Terry Reedy" <tjreedy at home.com> writes:
> "> The obvious workaround is to define a function that calls the
> appropriate
> > constructor, e.g.
> >   def newpoly(sides):
> >     if sides==3: return Triangle(...)
> >     ...
> 
> A factory function like this is a standard solution that has been
> discussed in several posts on this list.  Don't knock it.

I'm not knocking it, I just don't see how to extend the class from
additional base classes without having to add more special code to
the factory function, which is against the OO spirit.  Any thoughts?



More information about the Python-list mailing list