mirror of
https://github.com/rjNemo/design-patterns
synced 2026-06-06 10:36:39 +00:00
* doc: create package & update general TOCs * doc: add documentation * add code example * reformat using black
18 lines
570 B
Python
18 lines
570 B
Python
"""
|
|
Concrete Observers react to the updates issued by the Subject they had been
|
|
attached to.
|
|
"""
|
|
from behavioral.observer.observer import Observer
|
|
from behavioral.observer.subject import Subject
|
|
|
|
|
|
class ConcreteObserverA(Observer):
|
|
def update(self, subject: Subject) -> None:
|
|
if subject.state < 3:
|
|
print("ConcreteObserverA: Reacted to the event")
|
|
|
|
|
|
class ConcreteObserverB(Observer):
|
|
def update(self, subject: Subject) -> None:
|
|
if subject.state == 0 or subject.state >= 2:
|
|
print("ConcreteObserverB: Reacted to the event")
|