[Zope3-Users] Re: Renaming and OrderedContainer
j.kartnaller at cable.vol.at
Mon Jan 31 00:59:08 EST 2005
Garrett Smith wrote:
> jürgen Kartnaller wrote:
>>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.
More information about the Zope3-users