The "Gossip" example for the Observer Pattern

COM1204, Summer 2003, Professor Futrelle

Version of 28 June, 2003


What this is about

In the Observer Pattern, events are propagated so that each "listener" or "Observer" that wishes to be notified is sent a message when the event occurs. This is done by allowing the Observer to register itself with a dispatching entity. This is quite common in GUIs where mouse clicks and keystrokes can trigger a variety of events.

In this "Gossip" example I've constructed, a person can register to listen to talk originating from various places. When talk occurs at a place, all registered listeners are notified. In this example, people are both the originators of messages (they talk) and the listeners to them, so their class is called TalkerListener. The basic Gossip class sets up the system and has people "talk". What they hear and where they hear it from is printed to stdout.

Basic links:

Here's a brief note on Events in Java Swing, such as clicking on buttons, etc. Much more on this can be found by googling for
java swing tutorial events


Go to the COM1204 code examples page.

Return to Prof. Futrelle's home page