forked from Sean-Bradley/Design-Patterns-In-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.py
28 lines (20 loc) · 851 Bytes
/
client.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
"Observer Design Pattern Concept"
from data_model import DataModel
from data_controller import DataController
from pie_graph_view import PieGraphView
from bar_graph_view import BarGraphView
from table_view import TableView
# A local data view that the hypothetical external controller updates
DATA_MODEL = DataModel()
# Add some visualisation that use the dataview
PIE_GRAPH_VIEW = PieGraphView(DATA_MODEL)
BAR_GRAPH_VIEW = BarGraphView(DATA_MODEL)
TABLE_VIEW = TableView(DATA_MODEL)
# A hypothetical data controller running in a different process
DATA_CONTROLLER = DataController()
# The hypothetical external data controller updates some data
DATA_CONTROLLER.notify([1, 2, 3])
# Client now removes a local BAR_GRAPH
BAR_GRAPH_VIEW.delete()
# The hypothetical external data controller updates the data again
DATA_CONTROLLER.notify([4, 5, 6])