Observable properties: A means to track state changes in Java objects
An example application of the Observer design pattern using Java In one of my recent pet projects I needed objects that should be "aware" that one or more of their properties had changed. The obvious way to do it of course is to write code inside the "setter method" of each property and call whatever code must be executed in the event of a change. Something like that: void setName(String name) { this.name = name; onNameChanged(); } void onNameChanged() { // do whatever is necessary here } But what I really wanted was to attach an "on change" event to some of the object's properties and handle this event in a systematic way. I thought this was a valid opportunity to use the Observer design pattern and have the properties of the object notify their owner that they had changed. We can assume that each property is not any more a simple object of a given type T, but an instance of an "observable object" that contains a value of type