next up previous
Next: Inheritance and code reuse
Up: MM company example
Previous: MM company example

Adding behaviour via inheritance

The specification above is underdetermined, in that we have not specified any actual values for the attributes. We shall do so now, by defining a particular company, bogo_rex:

object bogo_rex {
  inherits( company )
  incomings[0] = 10000 &
  (t>0) incomings[t] = incomings[t-1]*1.1 &
  outgoings[0] = 5000 &
  (t>0) outgoings[t] = outgoings[t-1]*1.5
}

The inherits indicates that bogo_rex ``inherits'' from company, meaning it has the same attributes and the same equation relating them. It also gets some extra equations. The ...[0] equations specify initial values for incomings and outgoings, and the (t>0) ones specify values at times greater than zero in terms of the previous value.

For simplicity, all examples in this paper will assume that time starts at 0 and runs on for ever. However, it is possible --- and necessary, in real models --- to use other ranges.



Jocelyn Ireson-Paine
Sat Nov 28 17:42:14 GMT 1998