Using decorators to implement Observer Pattern in Python3
问题 This question is not in general about the observer pattern. It is focused on the use of decorators in that pattern. The question is based on the answer of a similar question. #!/usr/bin/env python3 class Observable: """ The object that need to be observed. Alternative names are 'Subject'. In the most cases it is a data object. """ def __init__(self): self._observers = [] def register_observer(self, callback): self._observers.append(callback) return callback def _broadcast_observers(self,