pure virtual functions in python
Chad Netzer
cnetzer at mail.arc.nasa.gov
Mon Jan 13 17:17:25 EST 2003
> class AbstractSomething:
> def __init__(self, ...):
> if self.__class__ is AbstractSomething:
> raise NotImplementedError
> ...
>
> class ConcreteSomething(AbstractSomething):
> def __init__(self, ...):
> AbstractSomething.__init__(self, ...)
>
> This will prevent people from creating AbstractSomethings directly,
> but they'll have no problem calling the AbstractSomething.__init__
> method from a subclass.
Awesome. I was doing this by using a separate initializing method, but
your version has some real advantages. Thanks for the great idea
(simple and elegant; no wonder I missed it. :).
--
Bay Area Python Interest Group - http://www.baypiggies.net/
Chad Netzer
cnetzer at mail.arc.nasa.gov
More information about the Python-list
mailing list