[Zope3-dev] Containment constraints

Jim Fulton jim at zope.com
Wed Dec 24 09:11:35 EST 2003


Roché Compaan wrote:
> * Jim Fulton <jim at zope.com> [2003-12-23 23:00]:
> 
>>Roché Compaan wrote:
>>
>>>The containment constraints are yummy. Just one thing I am concerned
>>>about is that the current implementation (__setitem__.precondition on an
>>>Interface) may lead to a lot of dead chickens. I seem to be ending up
>>>with a lot of interfaces that only subclass IContainer and set
>>>preconditions.
>>
>>Yes, and likewise for the __parent__ constraint.
>>
>>
>>>Add to that the class implementation and ZCML one has to
>>>write for each interface and the dead chickens start to smell.
>>
>>The zcml one has to write?  I don't follow this.
> 
> 
> To register the class as content, set permissions on it and provide
> views for it.

OK, but that's true of any content.  This is information that has to
be provided one way or another.  It certainly doesn't qualify as a
dead chicken.

> Sidnei suggested a smarter precondition but I suspect that this will
> make the interface less explicit about what types are allowed in a
> container. Here is an example of what I am doing:
> 
> I have an IOrganisation that may contain IBranches, IContactNumbers,
> IFinancialAccounts, etc that in turn may contain IBranch,
> IContactNumber, IFinancialAccount.
> 
> class IBranches(IContainer):
>     u"""A container to define the branches, franchisees, etc. of the
>         customer.
>     """
> 
>     def __setitem__(name, object):
>         u"""Add the given object to the container under the given
>         name."""
> 
>     __setitem__.precondition = ItemTypePrecondition(IBranch)

You probably also want to extend IContained and redefine
__parent__ to have a constraint that the parent must
be an organization.

And likewise below.

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 Zope3-dev mailing list