[Zope] Using Interface module
Terry Hancock
hancock@anansispaceworks.com
Tue, 29 Apr 2003 20:36:42 -0700
I'm trying out the Interface module that comes with Zope
and is highly recommended by the ZDG and a number of
how-tos for product developers.
It seems, though, that there are some fuzzy areas specific
to Zope, and I'm wondering if anybody has some wisdom
on the "best practices" in these cases:
1) An interface contains several factory-function generated
methods -- ZSQL, DTML, or images.
For example, I have a "pluggable brain" interface that
wraps a product in a store -- the caller doesn't know
exactly how the object should be displayed in a listing,
because it doesn't know what kind of object it is. So, the
object provides DTML snippets to render itself in a
selected range of representational intents -- from full
display to a brief catalog listing. Obviously this code
will break if the object does not provide the appropriate
DTML method -- so we need to include it in the interface
spec.
But what is it? Technically it's a method, so maybe I
should use the method interface definition approach:
def my_dtml_form(part_num=0, **kw):
"""Represents a part."""
But it looks more like an attribute when you define it --
do I lose anything by using one or the other representation?
(Obviously Attribute() doesn't give me the call signature --
anything else to consider?).
2) Sometimes, especially with factory methods, the methods
and/or attributes needed are bound inside of __init__ (i.e.
they're instance methods, not class methods). Nevertheless,
they are a requirement for the interface. Should they be
listed in the interface? Will the verification methods be
able to figure this out when judging whether an instance
will implement the interface? Will valid classes fail
because they don't list class attributes for these?
3) Finally, can I run some kind of self-verification step on
Zope import so that warnings or errors will result when a
Product with broken implementations (i.e. objects don't
implement the interfaces they publish)? That seems like
it would be very useful for quality control purposes --
especially in an open-source project where many independent
people of varying skill level might be modifying the code.
It would make it a lot easier for developers if they could
just get feedback on import.
Any thoughts appreciated. I'm really new to the interfaces
concept, but I like the idea.
Cheers,
Terry
--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks http://www.anansispaceworks.com