[Zope3-dev] Re: Container interface issues

Jim Fulton jim at zope.com
Wed Sep 10 15:15:01 EDT 2003


Garrett Smith wrote:
> Jim Fulton wrote:
> 
>> Anthony Baxter wrote:
>>
>>>>>> Jim Fulton wrote
>>>>
>>>>
>>>>
>>>> I proposed that application code, rather than containers, be
>>>> responsible for generating events and calling necessary hooks when
>>>> adding or removing objects.  
>>>
>>>
>>>
>>>
>>> I understand the rationale for it (indeed, I can't see a better way) but
>>> this makes me uneasy. In the process of hooking up the catalog I found a
>>> number of existing places that were not Doing The Right Thing with event
>>> generation - making more places to do this Would Be Bad. Tracking down
>>> missing event generation stuff also sucks - things are just wacky, and
>>> it takes some time to find the problem.
>>
>>
>>
>> I suspect that this would be almost as likely of Doing The Right Thing
>> was the container's responsibility.
>>
>> I think we can arrange for making Doing The Right Thing easier.  For 
>> example,
>> instead of:
>>
>>   container.setObject(name, object)
>>
>> people will use:
>>
>>   zapi.add(container, name, object)
>>
>> I think that these are of comparable difficulty.
> 
> 
> I would expect to see an adapter used here:
> 
>   container = zapi.getAdapter(container, IStandardNotifyContainer)
>   container[name] = object
> 
> This way, notification policies could be encapsulated in specific 
> adapters.

zapi.add simply gets the adapter and calls it.  There is still
indirection through adapters.



 > There would be little impact on existing code since containers
> are usually 'adapted' to IZopeContainer.

No, not any more.  This adaptation was happening as a result of
context wrapping. There is no longer any context wrapping. The
adapters have to be called explicitly.  IZopeContainer was too
course-grained.

> I personally would not be comfortable with zapi.add because of its opacity.

It's not opaque, as it is effectively a macro for:

   zapi.getAdapter(container, IAddTarget).addObject(name, object)

Jim

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





More information about the Zope3-dev mailing list