* Implemented more granular registration of observers with HashMap; Key: Event, Value: List of Observers registered for the event; * Edited constructors and super calls of all EventEmitter extenders * Edited constructor calls in App.java * Edited EventEmitterTest * Added new white walkers event, scout emits at wednesday, varys observes and emits at saturday * Added white walkers event to KingsHandTest.java * Varys now passes events * Corrected some indentation levels and added curly braces to if statements * Corrected some styling * Switched lines in App.java, added javadoc to registerObserver * Fixed some indents, added param comments
layout, title, folder, permalink, categories, language, tags
layout | title | folder | permalink | categories | language | tags | |
---|---|---|---|---|---|---|---|
pattern | Event Aggregator | event-aggregator | /patterns/event-aggregator/ | Structural | en |
|
Intent
A system with lots of objects can lead to complexities when a client wants to subscribe to events. The client has to find and register for each object individually, if each object has multiple events then each event requires a separate subscription. An Event Aggregator acts as a single source of events for many objects. It registers for all the events of the many objects allowing clients to register with just the aggregator.
Class diagram
Applicability
Use the Event Aggregator pattern when
- Event Aggregator is a good choice when you have lots of objects that are potential event sources. Rather than have the observer deal with registering with them all, you can centralize the registration logic to the Event Aggregator. As well as simplifying registration, a Event Aggregator also simplifies the memory management issues in using observers.