All the examples discussed so far have one feature in common:
The model stores values that influence the appearance of a view.
To synchronize stored values with their visual representations, the model sends a changed message to itself every time a value changes.
The model observers are informed about that change, examine the model state and update themselves.
This is a very frequent pattern and therefore it is inplemented as a small class of its own, the ValueHolder.
A ValueHolder stores one single value. Being a subclass of Model, a ValueHolder also maintains a (possibly empty) collection of observers. The observers are notified each time the value is changed.
The use of a ValueHolder as a model component is straightforward:
First of all, a ValueHolder is created and assigned to an instance variable:
var := ValueHolder new.
A newly created ValueHolder contains the initial value nil.
The message value: is sent to alter the value stored in the ValueHolder:
var value: 'Hello World'.
The value that is currently stored in a ValueHolder can be accessed with the message value.
var value.
In the next secition we rework the last example for use with value holders. We will use two value holders, one to store the temperature in centigrade and one to store the same temperature in fahrenheid.