-
Notifications
You must be signed in to change notification settings - Fork 1
/
mvc_observable.py
45 lines (31 loc) · 1.27 KB
/
mvc_observable.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
#!/usr/bin/python
import mvc_observer as o
class MVCObservable(object):
"""
The MVCObservable class is the parent class of the specific models which are acting as the core of the Model-View-Controller (MVC) Architecture and inherit from this class. It contains the main data and delivers interfaces to register and remove observers.
"""
_observers = []
def __init__(self):
""" Constructor of MVCObservable and default values will be initialised. """
# call constructor of parent class
self._observers = []
@property
def data(self):
""" Return core data. """
return self._data
@data.setter
def data(self, data = None):
""" Set core data. """
self._data = data
def add(self, observer):
""" Register an observer (MVCObserver-object). """
if observer != None:
self._observers.append(observer)
def remove(self, observer):
""" Remove an observer from the list of registered observers (MVCObserver-object). """
if observer != None:
self._observers.remove(observer)
def notify(self):
""" The general interface to notify observers about a data change. """
for observer in self._observers:
observer.update()