[Zope-dev] Re: [Zope3-dev] Interfaces in Zope 2.5, 2.7, and 3.x

Jim Fulton jim at zope.com
Mon Mar 1 10:32:07 EST 2004


Terry Hancock wrote:
> I have a product that uses a component/interface model
> internally.  I wrote this against the "scarecrow" Interface 
> module in Zope 2.5.1.

Cool.

> However that module has limitations.  One particular one is
> what I call a "SubInterface" -- which is a special case of 
> Interface.Attribute (a subclass of it) that asserts that an
> object contained within a parent interface implements a
> particular interface.

(Note that I responsed to this in the "Sub Interfaces" thread
  on zope3-dev, if anyone's intereested. :)


> Anyway, I wrote my own interface module to do this,
> extending the Interface module in Zope 2.5.1 (which lacks
> this feature).  All of my code actually imports interface support
> from my module instead of directly from Interface.
> 
> For unrelated reasons, though, I had to upgrade to Zope 2.7
> (and someday, I imagine I'll want to consider moving to Zope 3.x).
> 
> My first attempt with Zope 2.7, though yields total breakage!
> 
> The Interface module has been extensively overhauled, method
> names changed, etc. After giving up on "just fixing a few name-
> changes", which seems to be woefully inadequate, I decided to
> try to lift the old Interface module -- but now Zope reads the 
> "__implements__" attribute and isn't happy if it isn't one of its own
> interface objects!

....

Sorry about that.

These changes were made for Zope 2.6.  I'm pretty sure the changes
were made before the Zope 2.6 beta cycle.  Nobody complained
then, so I assumed I hadn't broken anything. :)

> Now, I can implement a new module based on the Zope 2.7 Interface -- but
> a close look at that seems to show that it, too, is rather experimental (lots of
> stubs, not-yet-implemented attributes, etc).  So I'm also sort of interested in
> the "interface" module in Zope X3.

We discussed this on zope3-dev and came to the conclusion that you
want to use Zope 3 interfaces and schema.  Zope 3 interfaces will become
standard in Zope 2 in Zope 2.8.

> It appears that some new bells and whistles have been added to the
> Interface module (e.g. what's a "superinterface"?).   Any chance, I'm
> wondering if "SubInterface" is now redundant?
> 
> Also, is there a general guide to "best practice" of using / learning the
> Interface module?  I note there are now interfaces defined for the interface
> module (cool!), and it looks like some self-documentation has been
> implemented.
> 
> The biggest problem (and this seems to be the usual problem with
> "self-documenting" tools) is that there doesn't seem to be a "start here"
> defined anywhere.  So you wind up starting somewhere in the middle and
> wasting a lot of time trying to decipher the big picture from lots of details,
> which is backwards. It'd be nicer if there was a "README" to get you started
> on this, maybe define some jargon, etc. 

Yes, that would definately help.  We've been doing that a lot elsewhere.

 > It's really hard to infer what the
> overall design concept is by only looking at these details -- in particular,
> I want to know what was conceptually changed from the older Interface
> module in 2.5.1.

Well, we probably won't help you there. That was too long ago, sorry.

Of course, the version in 2.5 was pretty close to the scarecrow proposal.
Presumabley, if you had a README.txt, you could do the conceptual diff yourself.


> This seems to also be a problem with combining Zope 3 and Zope 2
> interfaces, as was suggested by a post on the Zope3 mailing list:
> 
> http://mail.zope.org/pipermail/zope3-dev/2003-December/009023.html
> (and following -- note that "__interfaces__" should read "__implements__"
> in the original post).
> 
> Martijn's suggestion was to use an alternate name for the "__implements__"
> attribute.  I suppost I could do that -- call mine "__narya_interfaces__", but
> that sounds ugly.  In particular, I don't really want my interfaces module
> to actually *conflict* with Zope's.

As I mentioned on the zope3-dev list, you want to use the facade Interface
from (Packages3/Interface) in Zope 2.7. This is a bit of a pain to set up.
The facade will be a standard part of Zope 2.8.


> I also note that the post from the Zope3 list suggests that I shouldn't
> really be directly assigning "__implements__", but using something called
> "implements()".  Hmm. That's different too -- is there any good starting
> place for understanding Zope3's "interface" module?

See zope.interface.interfaces in a zope 3 checkout. See particularly the
declaration api.

> And how different are the Zope 2.7 / Zope X3 interface modules?  If I
> re-write my module to conform to Zope 2.7, will I just have to do it
> again?

You should write it against the Zope 3 interfaces.

> Could I instead leap ahead and use the Zope X3 interface module in
> Zope 2.7?

Yes.

> Also, since I'm posting to Zope3-dev as well -- what do you think of the
> SubInterface concept? 

As we discussed on zope3-dev, it's a great concept.  That's why we implemented
it with the Object scema field type. :)

 > Should I be contributing code directly to Zope X3's
> interface instead of subclassing it?

Absolutely!

Jim

-- 
Jim Fulton           mailto:jim at zope.com       Python Powered!
CTO                  (540) 361-1714            http://www.python.org
Zope Corporation     http://www.zope.com       http://www.zope.org




More information about the Zope-Dev mailing list