parent-child object design question

manstey manstey at csu.edu.au
Wed Jan 31 00:15:53 EST 2007


Hi Ben,

Could I also do something like the following? What does it mean to
store the parent class as a private variable in the child class?

class CacheProperty(object):
        def __init__(self, obj, parent, properties=None):
            self.__data = obj
            self._parent = parent
            if properties is None:
                properties = {}
            self._accumulate_properties(properties)


        def _accumulate_properties(self, properties):
            self.properties = []
            for key, val in properties.iteritems():
                setattr(self, key, val)
                self.properties.append(key)


        def __getattr__(self, name):
            return getattr(self.__data, name)

        def set(self, property):
            return self._parent.set(property)

the set function allows us to call the parent set function within the
child, which is what we need to do.






More information about the Python-list mailing list