ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-list
python-list
Re: Interfaces != Multiple Inheritance [was Re: python development practices?]
by Luigi Ballabio other posts by this author
Oct 31 2001 10:35AM messages near this date
Re: Interfaces != Multiple Inheritance [was Re: python development practices?] | Re: python development practices?
At 06:35 PM 10/30/01 -0800, Paul Rubin wrote:
> Richard Jones <richard@[...].au> writes:
>  > Java interfaces != multiple inheritance.
>  >
>  > They address completely different issues. Mutliple inheritance allows one
>  > to include functionality from multiple base classes in one step. An
>  > interface indicates that your class implements a specific set of methods.
>  > Interfaces don't implement functionality, therefore indicating that your
>  > class implements multiple interfaces doesn't add any additional
>  > functionality.
> 
> 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.  Then
> make the implementation for your inheriting class supply real versions
> of all the operations.

Why would you want to do that in Python?

The interface mechanism is needed in Java due to its type checking---if you 
declare a function as f(Interface i), then an object needs to implement 
Interface to be accepted by f as an argument. The same applies to C++ and 
purely abstract base classes. There is no such requirement in Python: you 
just write f(i) assuming that i implements the needed methods, and the 
interpreter will raise an error if i doesn't. The principle is the same 
(well, alike) as C++ templates.

Bye,
         Luigi


-- 
http://mail.python.org/mailman/listinfo/python-list
Thread:
Peter Wang
Peter Hansen
Toby Dickenson
Tim Peters
Steve Holden
Steve Holden
Cliff Wells
Tim Peters
Martijn Faassen

Cliff Wells
Cliff Wells
Martijn Faassen
Martijn Faassen
Paul Rubin
Russell E. Owen
Barry A. Warsaw
Martijn Faassen
Peter Wang
Skip Montanaro
John Roth
David Bolen
Peter Wang
Peter Wang
Skip Montanaro
Chris Tavares
Darren Collins
David Bolen
Paul Rubin
Paul Rubin
Peter Wang
F Basegmez
Richard Jones

Richard Jones

Neal Norwitz
Graham Ashton
Peter Wang
Russell E. Owen
Skip Montanaro
Cliff Wells
Hung Jung Lu
Wade Leftwich
Peter Wang
Peter Wang


Peter Wang

Chris Gonnerman
Paul Rubin
Andrew Dalke
Paul Rubin
Luigi Ballabio
Paul Rubin
Tim Peters
John Roth
Paul Rubin
Richard Jones

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved