| 32 | |
| 33 | |
| 34 | class ConcreteMediator(Mediator): |
| 35 | def __init__(self, component1: Component1, component2: Component2) -> None: |
| 36 | self._component1 = component1 |
| 37 | self._component1.mediator = self |
| 38 | self._component2 = component2 |
| 39 | self._component2.mediator = self |
| 40 | |
| 41 | def notify(self, sender: object, event: str) -> None: |
| 42 | if event == "A": |
| 43 | print("Mediator reacts on A and triggers following operations:") |
| 44 | self._component2.do_c() |
| 45 | elif event == "D": |
| 46 | print("Mediator reacts on D and triggers following operations:") |
| 47 | self._component1.do_b() |
| 48 | self._component2.do_c() |
| 49 | |
| 50 | |
| 51 | class BaseComponent: |