[Zope3-dev] persistence by adaptation, and aop?

Steve Alexander steve@cat-box.net
Tue, 03 Jun 2003 20:08:29 +0300


Ken Manheimer wrote:
> In jon udell's latest column, he notices a pattern in several flavors
> of java object persistence mechanisms - an aspect-oriented programming
> characterization.  It got me to thinking about how we continue to do
> persistence as a mixin for objects, and wondering whether we could do
> it with our alternative to AOP, adapters...  I don't know enough about
> components' innards to judge, and am wondering what those i in the
> know think of the idea?

On a related note, I've been doing a lot with proxies recently.

I think it should be possible to achieve a similar effect to the 
Persistent base class by using a proxy that rebinds the "self" of 
methods and properties, and detects changes to the object.

So perhaps something like this:

   obj = SomeNonPersistentClass()
   pobj = PersistenceProxy(obj)
   pobj.doSomething()

The code to doSomething might look like this:

   class SomeNonPersistentClass:

     def doSomething(self):
         self.foo = 'bar'

When doSomething() is called via the proxy, the 'self' argument is not 
obj, but is instead another proxy around obj that hooks __setattr__ and 
does the right things.

--
Steve Alexander