Wednesday, October 24, 2007

Example of the Observer Pattern

The first thing that came to my mind after reading about the observer pattern was a program that Dondi showed our class in CMSI 370 (Interaction Design) called drip. This program had multiple "meters" that used the same data, so when one meter was manipulated, all the other ones would be changed as well. This can be done with the observer pattern without tightly coupling objects. An example I found in the java core api was actually the interface called Observer. Classes that implement Observer are notified of changes that happen to objects that are observable.

1 comment:

Dondi said...

OK, that's a decent-enough write-up on how Java's Observer interface serves as an example of, well, the Observer design pattern. If we count what you mentioned regarding ActionListener and the Command pattern (though, as commented there, an even stronger example exists), that's two patterns by October 24, not six by October 23, as previously agreed upon. Pedal to the metal now, please.