Different implementations of the observer
The following implementations are available for the observer pattern:
- Event dispatcher/listener
Let's understand both the implementations in detail.
The event dispatcher/listener (event emitter) implementation allows broadcasting data to more than one consumer.
EventEmitter can be inherited in the case of more than one event represented by one object. We can use the
on function for the
EventEmitter implementation in the observer pattern to define objects for listening to an event. Objects in the event dispatcher implementation uses custom events that can be inherited from an event dispatcher object. It uses different kind of strings to identify the type of the event. ...