Design Pattern Examples
Overview of object-oriented design patterns
observer_class.py
Go to the documentation of this file.
9
10from .observersubject_numberproducer import IObserverNumberChanged, INumberProducer
11
12
13
16
17
23 def __init__(self, numberProducer : INumberProducer) -> None:
24 if not numberProducer:
25 raise ValueError("The ObserverForDecimal constructor requires a valid INumberProducer object.")
26 self._numberProducer = numberProducer
27
28
30
31
32
38 def NumberChanged(self) -> None:
39 number = self._numberProducer.FetchNumber()
40 print(" Decimal : {0}".format(number))
41
42
43
45
46
47
50
51
57 def __init__(self, numberProducer : INumberProducer) -> None:
58 if not numberProducer:
59 raise ValueError("The ObserverForHexaDecimal constructor requires a valid INumberProducer object.")
60 self._numberProducer = numberProducer
61
62
64
65
66
72 def NumberChanged(self) -> None:
73 number = self._numberProducer.FetchNumber()
74 print(" Hexadecimal: {0:#08X}".format(number))
75
76
77
79
80
81
84
85
91 def __init__(self, numberProducer : INumberProducer) -> None:
92 if not numberProducer:
93 raise ValueError("The ObserverForBinary constructor requires a valid INumberProducer object.")
94 self._numberProducer = numberProducer
95
96
98
99
100
106 def NumberChanged(self) -> None:
107 number = self._numberProducer.FetchNumber()
108 print(" Binary : {0:#032b}".format(number))
Represents an observer that prints out the current number from the Subject in binary.
_numberProducer
The number producer from which to get the current number.
None __init__(self, INumberProducer numberProducer)
Constructor.
None NumberChanged(self)
Called whenever the number is changed in the number producer.
Represents an observer that prints out the current number from the Subject in decimal.
_numberProducer
The number producer from which to get the current number.
None __init__(self, INumberProducer numberProducer)
Constructor.
None NumberChanged(self)
Called whenever the number is changed in the number producer.
Represents an observer that prints out the current number from the Subject in hexadecimal.
_numberProducer
The number producer from which to get the current number.
None __init__(self, INumberProducer numberProducer)
Constructor.
None NumberChanged(self)
Called whenever the number is changed in the number producer.