The IObserverNumberChanged, IEventNotifications, and INumberProducer interfaces, and the ObserverSubject_NumberProducer class used in the Observer Pattern. More...
#include <algorithm>
#include <memory>
#include <stdint.h>
#include <vector>
Go to the source code of this file.
Classes | |
struct | IObserverNumberChanged |
Represents an observer to the Subject class. An observer implements this interface and then subscribes to the Subject with the interface. The observer will be called whenever a change in the number is made. More... | |
struct | IEventNotifications |
Represents a Subject that takes observers implementing the IObserverNumberChanged interface. More... | |
struct | INumberProducer |
Represents the Subject to the observers. This is the minimum needed by observers to get access to the data provided by the Subject class. More... | |
class | ObserverSubject_NumberProducer |
Represents the Subject in this example, in this case, a class that contains a single number that is updated with a call to the Update() method. Whenever Update() is called, the number is incremented and all observers are notified. The observers then fetch the current number via the INumberProducer interface. More... | |
Namespaces | |
namespace | DesignPatternExamples_cpp |
The namespace containing all Design Pattern Examples implemented in C++. | |
Macros | |
#define | __OBSERVERSUBJECT_NUMBERPRODUCER_H__ |
The IObserverNumberChanged, IEventNotifications, and INumberProducer interfaces, and the ObserverSubject_NumberProducer class used in the Observer Pattern.
The Observer pattern is used when one or more entities need to be told about a change in state of another entity (typically known as the Subject) and those entities, upon notification, pull data from the Subject to complete their own specific tasks. Alternatively, the Subject could push the data to the observing entities. The example uses a pull approach.
The code in this file defines the Subject for the example. In addition, this file contains the interfaces needed for the observers and the Subject to interact "at arms length" from each other, so neither has any more information about the other than is strictly necessary.
Definition in file ObserverSubject_NumberProducer.h.
#define __OBSERVERSUBJECT_NUMBERPRODUCER_H__ |
Definition at line 22 of file ObserverSubject_NumberProducer.h.