[Zope3-dev] Containment constraints

Roché Compaan roche at upfrontsystems.co.za
Wed Dec 24 03:14:33 EST 2003


* 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.

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)


class IContactNumbers(IContainer):
    u"""A container to define all kinds of telecommunication lines for
        the customer. Example: faxes, landlines, mobiles, etc.
    """

    def __setitem__(name, object):
        u"""Add the given object to the container under the given
        name."""

    __setitem__.precondition = ItemTypePrecondition(IContactNumber)


class IFinancialAccounts(IContainer):
    u"""A container to define the financial accounts of the customer
    """

    def __setitem__(name, object):
        u"""Add the given object to the container under the given
        name."""

    __setitem__.precondition = ItemTypePrecondition(IFinancialAccount)


class IOrganisation(IContainer):
    u"""A container for defining the unique characteristics of a
        customer
    """

    [snip other schema fields]

    def __setitem__(name, object):
        u"""Add the given object to the container under the given
        name."""

    __setitem__.precondition = ItemTypePrecondition(IBranches,
        IContactNumbers, IEmailAddresses, IFinancialAccounts,
        IReferenceContacts, IRevenue, IURLs)


-- 
Roché Compaan
Upfront Systems                 http://www.upfrontsystems.co.za



More information about the Zope3-dev mailing list