Previous
Contents
Next

Using Value Holders - Introductory Remarks


All the examples discussed so far have one feature in common:

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.


Previous
Contents
Next