Declaration of the Observer_Exercise() function as used in the Observer Pattern. More...
Go to the source code of this file.
Macros | |
#define | __OBSERVER_EXERCISE_H__ |
Functions | |
void | Observer_Exercise (void) |
Example of using the Observer Pattern. | |
Declaration of the Observer_Exercise() function as used in the Observer Pattern.
Definition in file c/Observer_Exercise.h.
#define __OBSERVER_EXERCISE_H__ |
Definition at line 9 of file c/Observer_Exercise.h.
void Observer_Exercise | ( | void | ) |
Example of using the Observer Pattern.
The Observer pattern allows for one or more observers to react to changes in a Subject entity.
In this exercise, a number producer (the Subject) updates an internal value every time the NumberProducer_UpdateNumber() function is called. Three different observers are attached to the number producer and print out the current value in different formats whenever the number is changed.
Since functions are used as the observers of the NumberProducer object, the "push" model is used to push the updated number to each observer. Otherwise, the observers would have to be given the NumberProducer object so as to call a function to fetch the number from that object.
Definition at line 74 of file Observer_Exercise.c.
References NumberProducer_Create(), NumberProducer_Destroy(), NumberProducer_SubscribeToNumberChanged(), NumberProducer_UnsubscribeFromNumberChanged(), NumberProducer_UpdateNumber(), ObserverForBinary_NumberChanged(), ObserverForDecimal_NumberChanged(), and ObserverForHexadecimal_NumberChanged().