Monitoring State Changes Using Observer/Observable
As you will see in later chapters, Java relies heavily on the Model-View-Controller (MVC) paradigm. MVC stresses that data (a model) should be unaware of how it is used and displayed (by views), and that a third party (a controller) should coordinate their interaction. This chapter serves as a prelude to those concepts by introducing observables and observers.
The Observable Class
The Observable class allows an object to notify other objects when it changes. The concept of observables is borrowed from Smalltalk. In Smalltalk, an object can express interest in another object, meaning that it would like to know when the other object changes.
When building user interfaces, you might have multiple ...
Get Special Edition Using Java 2 Standard Edition 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.