Keeping all interested parties informed using the observer pattern
The observer pattern is sometimes known as the producer-customer pattern. Again, this is a very common use case that appears across applications and is therefore mentioned in the GoF’s book.
Motivation
A pattern represents a direct relationship between objects. One object has the role of the producer. A producer may have many customers to whom the information should be delivered. These objects are sometimes called receivers. When an observer changes its state, all the registered clients are informed of this change. In other words, any changes that occur to the object will cause the observers to be notified.
Finding it in the JDK
The observer pattern is another fairly commonly used pattern across JDK modules. An example is the Observer
interface from the java.base
module and the java.util
package. Although the interfaces have already been deprecated, they are still used through the Observable
class...