#include <CAVERNmisc_observer_c.hxx>
Inheritance diagram for CAVERNmisc_subject_c::
Public Methods | |
virtual | ~CAVERNmisc_subject_c () |
virtual void | attach (CAVERNmisc_observer_c *) |
virtual void | detach (CAVERNmisc_observer_c *) |
virtual void | notify () |
Private Attributes | |
list<CAVERNmisc_observer_c *> | m_ListOfObservers |
What is it for? The subject-observer design pattern is an object oriented alternative to callback functions. We can have multiple observers "watch" a single subject. An observer begins to watch a subject when the subject makes an "attach(&observer)" call. Everytime the subject calls its notify() method, all observers that are watching it will react by calling their update() method.
We do not instantiate the CAVERNmisc_subject_c and the CAVERNmisc_observer_c. Instead, the API user creates classes that inherit the properties of these two superclasses. The class that inherits the observer class properties should implement the update() method. The update method is a pure virtual function. Not implementing it would result in a compiler error.
@author: cavern@evl
@version: 12/1/99
|
Subject calls attach(&observer) to register the observer. After this, everytime the subject calls its notify() method, the registered observer reacts accordingly by calling its update() method.
|
|
Subject calls detach(&observer) to DEregister the observer.
|
|
Subject calls notify() to tell all watching observers to react accoringly. (Each watching observer will call its update method.) |