[Zope-dev] Adapters in Zope 2

santi at zetadb.com santi at zetadb.com
Tue Feb 10 06:38:41 EST 2004


>> I've been trying to add some extra functionallity to a Folder object
>> without inheriting, but I'm not able to make it work.
>
> First question is "Why?". Unless you want to change the fucntionality of
> *all* folder objects inheriting is the way to go.
>

For instance, If I've a repository of Folders and Files and I write two
applications using it.   In the first application I need an extra method
to obtain contained objects in some especific order, and in the second
application I need a different order.

I can write a new class inheriting from Folder with two diferent new
methods, but I think that this is not a good aproach.  If tomorrow I write
a new application with some other needings I should modify my
InheritedFolderClass.  I prefer to add this logic in each application,
using and adapter.

If all we create inherited versions of Folders, collaborations between
applications is more difficult.  I you have an application using a
repository of inheritedFolderA's and I have another one using
inheritedFolderB's, our applications can't use the same repository, what
would be possible using a repository of Folders and adapters in each
application.

>> Anybody knows if there is a way to use adapters in zope2 ?  Or, if
>> not, there is some other way to add functionallity on-the-fly, without
>> inheriting ?
>
> MonkeyPatching. Python is highly dynamic. You rewrite the methods to how
> you would like them, and then you replace them with a quick.
>
>   TheClass.OldMethod = NewMethod.
>
> And now you call the new method with
>   object = TheClass()
>   object.OldMethod()
> Very cool.

Yes, this is a possible way, but not so nice as Adapters (in my modest
opinion).

Thanks for your answer

Santi Camps
http://zetadb.sourceforge.net





More information about the Zope-Dev mailing list