[Tutor] Changing a class into a subclass
alan.gauld at freenet.co.uk
Fri Mar 25 10:02:03 CET 2005
> > single instance (or indeed no instances because you could
> > use a static method... or get really fancy and create a
> > meta-class!).
> or make it a static method of Building
Yes that's actually what I meant, but reading it back it
sounds like I meant static Factory method.... Ho hum.
> or get really simple and use a module-level function...
Yeah., but I did say if he wanted to be OOPish.
> > class Shack(Building):
> > def __init__(self,p1,p2...):
> > Building.__init__(self,...)
> > Building.register(self,'Shack', Shack)
> > ...rest of init...
> I think you want to register Shack before you ever create one.
Yeah, you are right. My way you register it every time you
create an instance. A single registration call right after
the class definition is probably better.
> or you could probably get tricky and do it in a metaclass...
I would do in Smalltalk but meta classes in Python are somewhere
that I haven't visited yet! :-)
More information about the Tutor