Interfaces != Multiple Inheritance [was Re: python development practices?]

Graham Ashton graz at mindless.com
Wed Oct 31 12:47:44 CET 2001


In article <mailman.1004520094.4879.python-list at python.org>, "Luigi
Ballabio" <ballabio at mac.com> wrote:

> At 06:35 PM 10/30/01 -0800, Paul Rubin wrote:
>>The idea is implement an abstract base class instead of an interface.
>>Define methods for all the operations you want your interface to
>>support, and make each method simply raise NotImplementedError.
> 
> Why would you want to do that in Python?

Imagine that you're writing a library that is to be used by others. Yes,
you've documented it, but they've not read it in full, or quite understood
it yet. They try and use part of your library but don't realise they need
to define some other method in order to sub class one of your classes
correctly.

They can either get an exception that says "no such attribute" or they can
get an exception saying "this thing isn't implemented". I'd suspect
immediately that I'd missed something in the later case and head off to
the docs.

-- 
Graham



More information about the Python-list mailing list