Implementing interfaces with inheritance, good or bad?

Tripp Scott tripps81 at yahoo.com
Tue Feb 26 12:16:58 EST 2002


Hm, perhaps what I wanted to say is that, agreeing to what is 
read on the Interfaces Wiki at Zope.org: interfaces and classes 
should be separate. Both can have inheritance mechanism. So we 
have interface inheritance, and implementation (normal class) 
inheritance. However, without direct language support, an 
Interface is most easily implemented using normal python class.

t


At 25/02/2002 23:56, Tripp Scott wrote:
>I just saw:
>
>  http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/68445
>
>in which interfaces are implemented using class, and a class 
>implementing one or more interfaces subclasses the interfaces 
>class(es). Now suppose class C implements two Interfaces, I1 
>and I2. Both interfaces define an operation foo(). In one case, 
>I want to instantiate C because of I1, and in other case, 
>because I need a class that implements I2. How does C implement 
>both foo() operations (since foo() will be implemented as a 
>method)? And how do I tell C that I want I1, or I2? With an 
>argument to __init__? Any other way?
>
>I prefer providing Interface lookup via other mechanism, like 
>with the __implements__ class attribute as done in Zope's 
>Interface module. But are there any advantages of interfaces 
>being done with inheritance?
>
>t





More information about the Python-list mailing list