Concrete classes that inherit from the abstract INotifier class must implement its protocol. This includes the following:
virtual INotifier& enableNotification(bool enable = true) = 0; virtual INotifier& disableNotification() = 0; virtual bool isEnabledForNotification() const = 0;
In general, notifiers are created in a disabled state, so they must be explicitly enabled before they can signal events. This allows time for notifier and connection instances to initialize themselves and related instances.
virtual INotifier& addObserver(IObserver& observer, const IInterest& interest); virtual INotifier& removeObserver(IObserver& observer) = 0; virtual INotifier& removeObserver(IObserver& observer, const IInterest& interest); virtual INotifier& removeAllObservers() = 0; virtual IObserverList& observerList(const IInterest* anInterest = 0) const = 0;
virtual INotifier& notifyObservers(const INotificationEvent& event) = 0;
While the classes providing notification must call this function, in many cases it makes sense that the responsibility be delegated to another class. For instance, in the IBM Open Class Library, this responsibility is typically delegated to handler classes.
The IStandardNotifier class implements the notifier protocol and provides the base support for nonvisual parts. For visual parts, the notifier protocol is implemented in subclasses of IWindow. The notification under the IWindow classes occurs primarily using the existing handler classes.
To implement notification, your new nonvisual part can either inherit from IStandardNotifier or contain an IStandardNotifier instance. To use inheritance, specify IStandardNotifier (or a derived notifier class) as the base class when you create the part in VisualAge. If you do not specify a standard notifier as the base class, VisualAge assumes you want the part to notify using containment and generates the appropriate source code by default.
You can override the notification behavior that is provided by default through containment; this requires you write some code to be included in the generated class code. Follow these steps:
fImpl = new MyImplementationSubclass();
Notifiers and Observers
Preparing for Code
Generation
