What is an Observer?

Observer Design Pattern

The essence of this pattern is that one or more objects (called listeners or observers) are registered to observe an event which is raised (or triggered) by the observed object (subject).

Observer pattern diagram Observer pattern diagram

Within the scope of the ProvideX plug-in, the ProvideX Event Manager is the subject object and it is responisble for instantiating the objects that have been registered as observers.

For simplicity, we have created a simple text file where each observer is registered. The Event Manager processes this file during initialization and loads each of the observers. As each observer is successfully loaded, it is added to the list of observers to be notified when events are triggered.

The initial implementation of the external observers will notify each observer for every event. A future implementation will allow each observer to identify the event(s) that it wishes to observe.

Each observer declares when it is to be notified of an event. There are currently three points within the processing of an event where this notification can occur. These are stated in relation to the standard logic that is implemented within the ProvideX plug-in. It is not possible to override or replace the built-in logic with the current implementation.

The event notification points are:

Before
The observer is notified before the built-in logic
After
The observer is notified after the built-in logic
Both
The observer is notified both before and after the built-in logic