Notification Classes

When an event requiring notification occurs, the notifier constructs an INotificationEvent object defining the type of event and sends it to any observers registered for that type of event. Each observer is responsible for handling the event as appropriate.

The following class objects establish a notification pattern between application objects:

Notifiers

The notifier classes provide two classes that support the creation of objects capable of communicating changes in their state to other objects.

Notifier objects are responsible for defining the list of their supported notification events, for managing lists of observers, and for notifying registered observers when an event of interest occurs.

 

Observers

Observer classes define the protocol used by observers to register for and receive notifications. The abstract base class IObserver is templatized into two versions: IObserverConnectionTo, which takes only the target notifier; and IObserverForConnectionTo, which takes both the target notifier and a specific event notification data type.

 

Interests

An observer uses the IInterest class to indicate the types of notification it wants to receive. IInterest provides helper functions that notifiers use to notify observers of the events they are interested in. A notifier uses IInterest and INotificationEventFor to pass event data to observers.

You can streamline your notification mechanisms by filtering the types of notification an observer receives. The notifier contains a set of notification IDs that defines all the possible types of changes, and observers can register to be notified only of the types of changes they care about. The following is the typedef provided for notification IDs:

typedef const char *INotificationId;

You use INotificationId to create simple strings that uniquely describe a particular type of change that might originate notifications. Interests and notification events use this ID to identify the type.

Notification Event Types

INotificationEvent encapsulates a single notification event. Notification event objects identify the notification type, and are passed from the notifier to the observers.

INotificationEventFor is a templatized class used for passing event data from a notifier to its observers.

The Notification Family of Classes

The following is a view of all the notification classes: