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

Adding attributes via inheritance

MM allows object specifications to be extended with extra attributes as well as with extra equations:

object company_and_workers {
  inherits( company )
  < workforce     : integer
    average_salary: real
  >
  outgoings[t] = workforce[t]*average_salary[t]
}

object parkinsons {
  inherits( company_and_workers )
  workforce[0] = 100 &
  (t>0) workforce[t] = workforce[t-1]*2 &
  average_salary[0] = 12000 &
  (t>0) average_salary[t] = average-salary[t-1]*1.5 &
  incomings[0] = 1000 &
  (t>0) incomings[t] = incomings[t-1] * 1.1
}

In this example, we have two stages of inheritance. The first adds two new attributes, workforce and average_salary, and an equation relating them, to create a new object, company_and_workers. (This is a naïve way to handle salary costs: we do so for simplicity.) Like the original company, company_and_workers is underdetermined: it's a generic object that could be useful in modelling a range of different companies.

In the second stage, we create a specific, fully-determined, company from company_and_workers by adding initial values and some growth laws.

It would be possible to combine these stages, creating parkinsons directly from company. In practice though, it could well be useful to have company_with_workers as a separate object for use in a number of different models.



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