import abc class OrmSubject(metaclass=abc.ABCMeta): @abc.abstractmethod def addObserver(self, ormObserver): pass @abc.abstractmethod def removeObserver(self, ormObserver): pass @abc.abstractmethod def notify(self, subject): pass class Observer(metaclass=abc.ABCMeta): @abc.abstractmethod def update(self, subject): pass class BaseOrm(OrmSubject): def __init__(self): self.__observers = [] def addObserver(self, ormObserver): print("Added: {0}".format(ormObserver)) self.__observers.append(ormObserver) def removeObserver(self, ormObserver): self.__observers.remove(ormObserver) def notify(self, object): for observer in self.__observers: observer.update(object) @property def id(self): return self.__id @id.setter def id(self, id): notify = True try: old = self.id notify = False except AttributeError as e: pass # print(e) # notify = False self.__id = id if notify: self.notify(self)