12from abc
import ABC, abstractmethod
48class IEventNotifications(ABC):
100class ObserverSubject_NumberProducer(IEventNotifications, INumberProducer):
111 for observer
in observers:
112 observer.NumberChanged();
142 return foundObserver != -1
None UnsubscribeFromNumberChanged(self, IObserverNumberChanged observer)
Call this with an observer to unsubscribe from the "number changed" event.
None SubscribeToNumberChanged(self, IObserverNumberChanged observer)
Call this with an observer to subscribe to the "number changed" event.
Represents the Subject to the observers.
None Update(self)
Update the number then notify all observers.
int FetchNumber(self)
Return the current value from the Subject.
Represents an observer to the Subject class.
None NumberChanged(self)
This is called whenever the number in the ObserverSubject_NumberProducer object is changed.
None UnsubscribeFromNumberChanged(self, IObserverNumberChanged observer)
A client calls this to unsubscribe an observer from this class instance so notifications are no longe...
_number
The number being maintained.
None _NotifyNumberChanged(self)
Helper method to notify all observers that the number has changed.
bool _ContainsObserver(self, IObserverNumberChanged observer)
Helper method to determine if the specified observer is already present in the list of observers for ...
_observers
The list of observers subscribed to this class instance.
None Update(self)
Update the number then notify all observers.
int _FindObserver(self, IObserverNumberChanged observer)
Helper method to retrieve the iterator to the specified observer if the observer is in the list.
None __init__(self)
Constructor.
int FetchNumber(self)
Observers call this method to fetch the current number.
None SubscribeToNumberChanged(self, IObserverNumberChanged observer)
A client calls this to subscribe an observer to this class instance for notifications about changing ...