How about "pure virtual methods"?

Mike Meyer mwm at mired.org
Sun Dec 19 20:32:40 CET 2004


Noam Raphael <noamr at remove.the.dot.myrea.lbox.com> writes:

> What I suggest is a new class, called notimplemented (you may suggest
> a better name). It would get a function in its constructor, and would
> just save a reference to it. The trick is that when a new type (a
> subclass of the default type object) is created, It will go over all
> its members and check to see if any of them is a notimplemented
> instance. If that is the case, it would not allow an instantiation of
> itself.

+0

Python doesn't use classes for typing. As Alex Martelli puts it,
Python uses protocols. So the client expecting a concrete subclass of
your abstract class may get an instantiation of a class that doesn't
inherit from the abstract class at all.

Or maybe the subclass is only going to use a subset of the features of
the abstract class, and the author knows that sum deferred methods
won't be invoked. The correct behavior in this case would be to allow
the subclass to be instantiated, and then get a runtime error if one
of the features the author thought he could skip was actually called.

Finally, in a sufficiently complex class hierarchy, this still leaves
you wondering through the hierarchy trying to find the appropriate
parent class that tagged this method as unimplemented, and then
figuring out which class should have implemented it - as possibly a
parent of the class whose instantiation failed is the subclass that
should have made this method concrete.

       <mike
-- 
Mike Meyer <mwm at mired.org>			http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.



More information about the Python-list mailing list