Implementing interfaces with inheritance, good or bad?
Tripp Scott
tripps81 at yahoo.com
Mon Feb 25 11:56:54 EST 2002
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