-
-
Notifications
You must be signed in to change notification settings - Fork 125
/
mediator_concept.py
48 lines (33 loc) · 1.13 KB
/
mediator_concept.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# pylint: disable=too-few-public-methods
"Mediator Concept Sample Code"
class Mediator():
"The Mediator Concrete Class"
def __init__(self):
self.colleague1 = Colleague1()
self.colleague2 = Colleague2()
def colleague1_method(self):
"Calls the method provided by Colleague1"
return self.colleague1.method_1()
def colleague2_method(self):
"Calls the method provided by Colleague2"
return self.colleague2.method_2()
class Colleague1():
"This Colleague provides data for Colleague2"
@staticmethod
def method_1():
"A simple method"
return "Here is the Colleague1 specific data you asked for"
class Colleague2():
"This Colleague provides data for Colleague1"
@staticmethod
def method_2():
"A simple method"
return "Here is the Colleague2 specific data you asked for"
# The Client
MEDIATOR = Mediator()
# Colleague1 wants some data from Colleague2
DATA = MEDIATOR.colleague2_method()
print(f"COLLEAGUE1 <--> {DATA}")
# Colleague2 wants some data from Colleague1
DATA = MEDIATOR.colleague1_method()
print(f"COLLEAGUE2 <--> {DATA}")