Python (well...Zope) Interfaces

by Jeremy Jones

I'm in the process of designing a workflow framework (in Python, of course). As I'm laying it out, it's helpful to think in terms of the types of the pieces that are going to interact with one another and what they can do. I've begun creating "base" classes which define empty methods which I plan on objects of corresponding "concrete" classes containing. This is all a nice thought experiment as it helps congeal some of my thoughts, but there is effectively no real value in implementing these empty base classes.

Some time back, I had read about Zope interfaces. I didn't really think much about them at the time, but now I'm giving thought to using them. Since the Python language does not provide linguistic constructs to specify an interface (at least, not like some languages do), I thought it might be helpful (if for no other reason than documentation and design) to use something like Zope interfaces to help build my workflow manager.

The alternative is to proceed as I had begun and lay out some empty "base" classes which will contain the methods which I expect "concrete" classes to contain. And rely on unit tests to enforce that instances of each concrete class will have the appropriate methods behaving in the appropriate way. (And I would assert that using unit tests is the right way to go even if you use "proper" interfaces.)

Now that I've layed out my situation, I have a question. Is there really any value to something like Zope interfaces? And if there really is benefit, is it merely documentational and design-oriented which could be achieved with convention without having to rely on a tool such as Zope interfaces? Please post your comments here, as I'm really interested in reading what others thing on the subject.

2 Comments

Michael Bernstein
2007-01-26 12:59:13
While Zope interfaces are useful for documentation and so on, if that were there only benefir I wouldn't consider them a good investment. Instead, you should consider the advantages you get in compositional flexibility by using them with adaptation.


Especially when devising (and using) a framework, Interfaces and Adapters really shine.

Rick Thomas
2007-01-27 21:25:20
Some insight here?


Masquerading and Adaptation Design Patterns in Python
http://www.aleax.it/Python/os04_pydp.pdf