parent-child object design question

manstey manstey at
Tue Jan 30 07:02:45 CET 2007


I am having trouble designing my classes.

I have two classes. The first one wraps around an old-style class 
called oref

Class CacheClass(object):
    def __init__(self, obj):
        self.__data = obj
    def __getattr__(self, attr):
        return getattr(self.__data, attr)

The second class is much the same, also wrapping, but has some 

class CacheProperty(object):
    def __init__(self, obj, dicProperties={}):
        self.__data = obj
        for key, val in dicProperties.iteritems():
            setattr(self, key, val)
        self.Properties = lisProperties
    def __getattr__(self, attr):
        return getattr(self.__data, attr)

Here is my code:

>>> MyClass = CacheClass(oref)
>>> MyProperty = CacheProperty(oref2,{'Name':'Surname', 'Value':'Peter'})
>>> setattr(MyClass,MyProperty.Name,MyProperty)

Now, the problem is that I want a method MyClass.MyProperty.Save() to 
save the value of MyClass.MyProperty to the database backend on disk, 
but the code for this is part of the wrapped oref code, and thus is 
invoked only by MyClass.set(MyProperty.Name,MyProperty.Value).

How can I access this method inside the MyProperty class?

I hope this is clear!


More information about the Python-list mailing list