A Classic Example: Observer in Swing
The most common case in which clients depend on changing objects occurs in graphical user interfaces. Whenever a user clicks a button or adjusts a slider, many objects in the application may need to react to the change. Java Swing anticipates that you will be interested in knowing when a user changes a Swing component, and the OBSERVER pattern is evident throughout Swing. Swing refers to interested clients as “listeners” and lets you register as many listeners as you like to be notified of a component's events.
Consider a typical Oozinoz application with a Swing GUI, such as the one that Figure 9.1 shows. This application lets a fireworks engineer experiment visually with parameters that determine the relationship ...
Get Design Patterns Java™ Workbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.