- Data Sharing
- The Publish-and-Subscribe Model
- Observers
- The ObserverEntity Class
- The Observer Pattern and the Java Language
- Messages from the Publisher to the Subscribers
- Separation of Concerns
- Running the Code
- Conclusion
- References
The Observer Pattern and the Java Language
Notice in passing that Listing 5 is in fact an example of the observer pattern taken from the Java language. By following this pattern, the actionPerformed() method waits patiently until the associated GUI element (the button ) is activated.
There is no need for complicated mechanisms for polling the status value of the Update Key Data button. Instead, use the code as illustrated in Listing 5: When the button is pushed, the associated method is called.
The nice thing about this separation between GUI elements and the backend handling code is independence. You can create a GUI that is as complex or simple as required, and the backend handlers use the observer pattern. The Java language also uses other patterns, such as the factory pattern.