September 18, 2002
The End of Inheritance

The End of Inheritance: Automatic Run-time Interface Building for Aggregated Objects is a fascinating new recipe on the Python Cookbook.

Knowing both Python and Java has made me think about the relationship between types, interfaces, inheritance and classes a lot more than knowing just one would have done, I think. It certainly seems to me that the central concept is the interface - what roles can the object take. This is quite a separate thing from inheritance - that's about behavior, what an object actually is.

A good example here is the Python concept of a 'file'. Any object which follows the file 'protocol' (or the required subset of that protocol which is actually used) can be used anywhere that a real file object can. You could do this in Java quite easily, by implementing 'file' using an interface, but people usually seem to use inheritance instead.

This recipe allows you to build a class composed of other objects (with a 'has-a' relationship), but to automatically implement the behaviors of the contained objects.

You can do something similar with Java's Dynamic Proxy Class API, as as Java 1.3.

Via the Python Daily URL.

Posted to Python by Simon Brunning at September 18, 2002 02:07 PM
Comments
Post a comment
Name:


Email Address:


URL:



Comments:


Remember info?