Observer


Introduction

           The observer-observable model is illustrated here : the general idea is to attach 'observers' to certain subjects. When there is a change in the subject the observers notice this and react to the change.

More about the Observer/Observable model?


CAVERNsoft classes used

    CAVERNmisc_subject_c

                This is the subject class. The user should create a class that inherits the properties of this class and should call the notify() method.

    CAVERNmisc_observer_c

                This is the observer class. Like the subject class, this class is not to be instantiated directly but should be inherited by a user defined class. The pure virtual function update() should be implemented by the class.

                The observer_sample.cxx uses two classes Player and Watcher which inherit the properties of  the super classes mentioned above. Player1 and Player2 are two subjects to whom a 'Watcher1' gets attached using the attach()  method. When either player calls the notify(), the watcher calls it's update() method.


Usage

        observer_sample
 

Output

    The two subjects Player1 and Player2 are attached to the observer Watcher. When both the subjects call their notify() method, the observers update method is triggered which in this case prints the following output
 
 Watcher reacting to Player1
 Watcher reacting to Player2

for more information email : cavern@evl.uic.edu