design-patterns/behavioral/mediator/concrete_mediator.py
Ruidy edcd5d35d7
Mediator (#18)
* doc: add documentation

* doc: edit general documentation

* add code example
2020-10-02 17:24:36 +02:00

20 lines
762 B
Python

from behavioral.mediator.components import Component2, Component1
from behavioral.mediator.mediator import Mediator
class ConcreteMediator(Mediator):
def __init__(self, component1: Component1, component2: Component2) -> None:
self._component1 = component1
self._component1.mediator = self
self._component2 = component2
self._component2.mediator = self
def notify(self, sender: object, event: str) -> None:
if event == "A":
print("Mediator reacts on A and triggers following operations:")
self._component2.do_c()
if event == "D":
print("Mediator reacts on D and triggers following operations:")
self._component1.do_b()
self._component2.do_c()