A few words about Python interfaces

Carlos Ribeiro cribeiro at mail.inet.com.br
Sun Apr 15 10:21:10 EDT 2001


At 00:46 15/04/01 -0700, Alex Shindich wrote:
>Zope can come with documentation on what methods should be implemented
>for Zope-compatible components, and users would be able to create such
>components even today. Also, Zope can provide a bunch of classes like:
>class MyZopeInterface:
>         """"""
>         def myZopeMethod (self, a, b, c):
>                 """The docs go here..."""
>                 raise MyZopeException, "Method 'MyZopeMethod' is not 
> implemented"
>         ...
>What's the big deal if users had to inherit from those classes?

Then we are back to the initial discussion, that is inheriting 
implementation vs. implementing interfaces. These are two different things. 
If we have to use class inheritance, we will need a abstract class. 
However, this is way to rigid as a approach. You end up with a much more 
confusing class hierarchy design. Sometimes, you end up being "forced" to 
used multiple inheritance, not because the objects are related, but because 
they have to support the same interface.

To explain it better: sometimes objects need to behave in a similar way, by 
implementing the same interface; however, they are not intrisecally related 
to the point the a common ancestor would be justified. Someone wrote an 
example of family with a Python programmer; I dont remember the details but 
it does illustrate my point.


Carlos Ribeiro






More information about the Python-list mailing list