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

Paul Rubin phr-n2001 at nightsong.com
Mon Sep 24 00:05:17 EDT 2001


"John Roth" <johnroth at ameritech.net> writes:
> > 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?
> 
> The thing is, that's exactly what a factory function is for - it
> does whatever special case logic is required to get the right class
> instantiated, so that the code doesn't have to be replicated
> elsewhere in the system.

Yes, however it doesn't completely solve the problem.  Roeland's
post using metaclasses does what I need--all I have to do now is
spend a few more hours poring over his post trying to understand it :).



More information about the Python-list mailing list