The Observable Class
Java provides an Observable class in java.util that is used in conjunction with an Observer interface that is implemented by interested Observer classes.
An Observable class is one in which we may be interested in knowing what is going on, but we don't want to hard code in business logic for this as the logic requirements may change over time.
In addition, this business logic may not really have anything to do with the internal encapsulated behavior of that class - and thus really doesn't belong in it. For example, we may want to monitor an Engine class's tempreture and make certain business decisions based on the value of that tempreture - like shutting the engine down if the tempreture reaches a certain value. But this sort of decision really doesn't rest in the Engine itself.
From an encapsulated object persepctive: the engine should not have any knowledge about these types of decisions. It only knows how to run. As a result of running, its tempreture is going to vary based on the load required of it. It may know its maximum safe operating temperature but not necessarily what to do if that temperature is exceeded. And code to deal with this does not belong in the Engine class.
Nor does it belong in another class to which the Engine class instantiates and uses methods on that class to monitor itself. That couples the two classes together and would be in violation of a major tennate of the object model.
When designing a class that extends Observable, all that is necessary is to provide a private ArrayList to store all of the objects that want to observe it. The Observable doesn't need to know anything about these objects. It just has a list containing them and can simply cast them as Observable when it loops through them to call the Observer interface's implemented update() method.
The Observer Interface
Java provides an Observer interface in java.util for just the purpose of building decoupled business service objects from those objects they will monitor, i.e. the Observable object. It has but one method: update(Observable observable, Object obj).
Note that the Observable object that calls the Observer's update method passes the Observer an instance of itself. This gives the Observer access to the Observable's methods.
The Engine Class
The Engine class extends Observable because it is what we want to look at and monitor. For the purposes of making our Engine class as simple as possible, it will only have one instance property for its temperature temp, and a static final int for its max operating temperature. It will also have an ArrayList for storing Observer objects.