Spaces:
Sleeping
Sleeping
File size: 501 Bytes
960cd20 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
from abc import ABC, abstractmethod
class Observer(ABC):
@abstractmethod
def update(self, *args, **kwargs):
pass
class Subject(ABC):
def __init__(self):
self._observers = set()
def attach(self, observer: Observer):
self._observers.add(observer)
def detach(self, observer: Observer):
self._observers.discard(observer)
def notify(self, *args, **kwargs):
for observer in self._observers:
observer.update(*args, **kwargs)
|