[Zope] Singleton and other design patterns in Zope

chrisf chrisf@fagmed.uit.no
Wed, 10 Jul 2002 18:31:40 +0200


A great many design patterns rely on changing class attributes.

class inst_counter:

        _instances = None

        def __init__(self,id):
                if inst_counter is None: inst_counter._instances = 0
                inst_counter._instances += 1
                self.id = id
                ......

class singleton:
    __instance = None
    class __hidden: pass

    def __init__(self,id)
            if singleton.__instance is None: singleton.__instance =
singleton.__hidden()

    then set __getattr__ and __setattr__ to point at
singleton.__instance()
    .....

Factories, Mediators, ....

Don't forget the Borg design pattern. :)

Pick up your Go4 design patterns and take a look on how may proven and
tested patterns rely on setting class attributes.
Yet, using Zope 2.5.1 I can't seem to get the persistence machinery to
recognize changes in class attributes.
Can this be done ? and how ?

Thanks Chris