The limitations of the GoF Observer pattern
The GoF pattern book was written at a time when the world was really doing sequential programming. The architecture of Observer pattern implementation had lot of anomalies, judging from the current programming model world view. Here are some of them:
- The close coupling between Subjects and Observers.
- The lifetime of the
EventSource
is controlled by the Observers. - Observers (sinks) can block the
EventSource
. - The implementation is not thread-safe.
- Event filtering is done at the sink level. Ideally speaking, the data should be filtered at the place where the data is (at the subject level, before notification).
- Most of the time, Observers do not do much and the CPU cycles will be wasted.
- The
EventSource
should ideally publish the value to the environment. The environment should notify all the subscribers. This level of indirection can facilitate techniques such as event aggregation, event transformation, event filtering, and canonicalizing the event data...