21#ifndef __OBSERVERSUBJECT_NUMBERPRODUCER_H__
22#define __OBSERVERSUBJECT_NUMBERPRODUCER_H__
176 observer->NumberChanged();
189 ObserversList::iterator foundIter;
203 ObserversList::iterator foundIter;
281 ObserversList::iterator foundIter;
Represents the Subject in this example, in this case, a class that contains a single number that is u...
uint32_t _number
The number being maintained.
ObserversList::iterator _FindObserver(const IObserverNumberChanged::shared_ptr_t &observer)
Helper method to retrieve the iterator to the specified observer if the observer is in the list.
ObserversList _observers
The list of observers subscribed to this class instance.
void UnsubscribeFromNumberChanged(IObserverNumberChanged::shared_ptr_t observer)
A client calls this to unsubscribe an observer from this class instance so notifications are no longe...
void SubscribeToNumberChanged(IObserverNumberChanged::shared_ptr_t observer)
A client calls this to subscribe an observer to this class instance for notifications about changing ...
uint32_t FetchNumber() override
Observers call this method to fetch the current number.
ObserverSubject_NumberProducer()
Default constructor.
void _NotifyNumberChanged()
Helper method to notify all observers that the number has changed.
void Update() override
Update the number then notify all observers.
bool _ContainsObserver(const IObserverNumberChanged::shared_ptr_t &observer)
Helper method to determine if the specified observer is already present in the list of observers for ...
std::vector< IObserverNumberChanged::shared_ptr_t > ObserversList
The namespace containing all Design Pattern Examples implemented in C++.
Represents a Subject that takes observers implementing the IObserverNumberChanged interface.
virtual ~IEventNotifications()
Virtual destructor required for interfaces in abstract classes.
virtual void UnsubscribeFromNumberChanged(IObserverNumberChanged::shared_ptr_t observer)=0
virtual void SubscribeToNumberChanged(IObserverNumberChanged::shared_ptr_t observer)=0
Represents the Subject to the observers. This is the minimum needed by observers to get access to the...
virtual void Update()=0
Update the number then notify all observers.
virtual uint32_t FetchNumber()=0
Return the current value from the Subject.
std::shared_ptr< INumberProducer > shared_ptr_t
Alias to make it easier to use this shared pointer.
virtual ~INumberProducer()
Virtual destructor required for interfaces in abstract classes.
Represents an observer to the Subject class. An observer implements this interface and then subscribe...
virtual void NumberChanged()=0
This is called whenever the number in the ObserverSubject_NumberProducer object is changed.
std::shared_ptr< IObserverNumberChanged > shared_ptr_t
Alias to make it easier to use this shared pointer.
virtual ~IObserverNumberChanged()
Virtual destructor required for interfaces in abstract classes.