> -----Original Message-----
> From: [EMAIL PROTECTED]
[mailto:python-
> [EMAIL PROTECTED] On Behalf Of Fuzzyman
> Sent: Friday, January 05, 2007 4:05 PM
> To: [email protected]
> Subject: Re: What is proper way to require a method to be overridden?
>
>
> Carl Banks wrote:
> > jeremito wrote:
> > > I am writing a class that is intended to be subclassed. What is
the
> > > proper way to indicate that a sub class must override a method?
> >
> > You can't (easily).
> >
>
> Well...
>
> How about not defining it on the base class, but check in the
> constructor that the attribute exists and that it is of type
> FunctionType ?
>
> Fuzzyman
> http://www.voidspace.org.uk/python/articles.shtml
>
> --
> http://mail.python.org/mailman/listinfo/python-list
Greetings:
Thomas Christopher's book "Python Programming Patterns" has an example
of this that I like. On page 72 he shows code for a class, AbstractSet,
which he later subclasses in ListSet and DictSet. Each of the methods
intended for subclassing simply to raise a NotImplementedError, e.g.:
def insert(self,x): raise NotImplementedError, "set.insert"
In this way the superclass's interface is well defined (the methods and
their parameters are all listed, but if invoked before they are
overwritten, they abort with a useful error message. Pretty slick,
IMHO.
Regards,
Barry
[EMAIL PROTECTED]
541-302-1107
________________________
We who cut mere stones must always be envisioning cathedrals.
-Quarry worker's creed
--
http://mail.python.org/mailman/listinfo/python-list