How about "pure virtual methods"?

Noam Raphael noamr at remove.the.dot.myrea.lbox.com
Wed Dec 22 01:02:41 CET 2004


Steve Holden wrote:
> Even if you can do it, how would you then implement a class hierarchy 
> where the ultimate base class had virtual methods, and you wanted to 
> derive from that class another class, to be used as a base class for 
> usable classes, which implemented only a subset of the virtual methods, 
> leaving the others to be implemented by the ultimate subclasses?
> 

What I suggest is that only *instantiation* would be forbidden. You are 
free to make a subclass which defines only some of the abstract methods, 
and to subclass the subclass and define the rest. You would only be able 
to make instances of the subclass of the subclass, but that's ok.

See Scott's implementation - the test at the end does exactly this.

I hope this helped,
Noam



More information about the Python-list mailing list