[Zope3-Users] Re: Renaming and OrderedContainer

Garrett Smith garrett at mojave-corp.com
Mon Jan 31 12:48:18 EST 2005


Jürgen, 

I think adapting the container to IObjectRenamer is the right thing.

Just reply to this with your new/modified files.

The tests should end up looking like those for ObjectMover and
ObjectCopier. I'd encourage you to give it a try -- there's a learning
curve, but you may find it as rewarding as writing adapters :) In any
event, we'll have to have them before committing to the trunk. (I'll
help if you need it.)

 -- Garrett

jürgen Kartnaller wrote:
> Garrett Smith wrote:
>> jürgen Kartnaller wrote:
>> 
>>> Hello all,
>>> I found the following problem when renaming objects :
>>> 
>>> zope.app.copypastemove.rename uses the ObjectMover to rename an
>>> object within a container. There is no problem as long as you are
>>> using BTree containers. 
>>> 
>>> If rename is used on an OrderedContainer then the object is moved to
>>> the end of the list because ObjectMover first adds the object with
>>> the new name to the container (OrderedContainer puts the new object
>>> to the end of the list) and then deletes the old name.
>>> 
>>> To solve this problem a container should have a rename function !
>> 
>> 
>> The problem is that copypastemove.rename doesn't use something like
>> IObjectRenamer. The default implementation of rename works fine for
>> normal containers, but not for ordered containers.
>> 
>> This would be straight forward to implement, if you're iterested :)
> 
> Of course it is, even for a zope3 newbie like me
> I added an IObjectRenamer (see below)
> 
>> 
>> A 'rename' method isn't z3onic (pronounced zee-thronic? ;) We like to
>> tack on new functionality using the component patterns, which have
>> some nice advantages over polymorphic methods.
> 
> Right, with this implementation I got the understanding of adapters.
> 
> 
> I added IObjectRenamer, implemented an ObjectRenamer (which is doing
> the same than the ObjectMover but only within one container).
> 
> What I found is :
> I need to implement an adapter for OrderedContainer.
> The problem now is, that I need to adapt to the container and not to
> the object I want to rename.
> IObjectMover and IObjectCopier are adapting to the object not to the
> container, which is ok for this case.
> For renaming I need to differentiate between different behavior of the
> container and not the object.
> So for IObjectRenamer I need to adapt to the container.
> 
> Is this right ?
> 
> I implemented OrderedContainerObjectRenamer as adapter for
> OrderedContainer. 
> 
> I love this adapter thing !!!
> 
> My question is now : (for my understanding of adapters)
> 
> Is an adapter allowed to do everything on the class it adapts ?
> I mean, should it only use the interface of that class or is it
> allowed to use internals of the class ?
> I did it in my adapter to directly access _order in OrderedContainer.
> 
> I now have a working implementation which passes the tests and, of
> cource, is doing what my application expects.
> I have no test for the OrderedContainer adapter because I don'nt know
> how to implement it.
> 
> I did my changes on the release version of zope3.
> Garret can you check it and if it seems good to you also commit it
> into the trunk ?
> I send my changes to you, just let me know your email.
> 
> 
> Jürgen
> 
> 
> _______________________________________________
> Zope3-users mailing list
> Zope3-users at zope.org
> http://mail.zope.org/mailman/listinfo/zope3-users



More information about the Zope3-users mailing list