[Zope3-dev] Re: Recursive containment constraints
Tres Seaver
tseaver at zope.com
Thu Sep 16 17:55:40 EDT 2004
Stephan Richter wrote:
> On Wednesday 15 September 2004 09:01, Dominik Huber wrote:
>
>>Month ago I read the contenttype part of stephan's book. at that time he
>>used
>>setTaggedValue to solve recursive containment constraints:
>>
>> 43 IMessage['__setitem__'].setTaggedValue('precondition',
>> 44
>>ItemTypePrecondition(IMessage))
>> 45 IMessage.setTaggedValue('__parent__', Field(
>> 46 constraint=ContainerTypesConstraint(IMessageBoard,
>>IMessage)))
>>
>>Today I wanted to use the setTaggedValue('__parent__', Field(...))
>>approach but it
>>seems not work anymore. Is that right?
>
>
> No, it should still work. I did not change to another pattern for technical
> reasons.
>
>
>> >>> '__parent__' in IMessage.names('all')
>> False
>>
>>The new version of the book solves this problem with two indepentent
>>interfaces IMessage
>>and IMessageContained. Is that the 'official' pattern people should
>>follow?
>
>
> Yeah, I think this is the recommended pattern. I changed to this one, since it
> is easier to read and understand. Also, all sample applications use this
> pattern as well.
In reality, I think we would be better off moving the constraint
declarations out of the classes; that would both remove the "forward
reference" problem and make it easy to move to a "containment constraint
registry" solution when that became available.
My biggest reason for wanting this is that the constraints are *policy*,
which might vary from site to site; making them intrinsic to the class
makes it harder to reuse the container / item classes in a site with
different policies. This consideration would suggest moving the
constraint declarations to ZCML, e.g.:
<content>
....
<contains interface=".interfaces.IFooItem" />
</content>
<content>
....
<container interface=".interfaces.IFooContainer" />
</content>
Tres.
--
===============================================================
Tres Seaver tseaver at zope.com
Zope Corporation "Zope Dealers" http://www.zope.com
More information about the Zope3-dev
mailing list