12.4 Representing parallel activities

In our computerized models we must be able to represent activities taking place in the application domain being modeled. Examples of such activities are deposit of money on a bank account, reservation of a seat on a flight, pushing a button, etc. In the previous chapters, we have seen how such activities may be represented by execution of methods and objects.

An activity is composed from single actions and the ordering in time of such actions is important. This is the case with the sequence of deposits and withdrawals on a specific bank account. The activities represented by execution of methods and objects in the previous chapters are all sequential.

Just as it is important to be able to describe that two activities or single actions are ordered in time, it is important to be able to describe that there is no ordering in time between them. The deposit of money in one bank account and the withdrawal of money from another may take place independently in the sense that it is not important to describe an ordering in time between the two activities.

In our computerized models we must therefore be able to model that a number of activities take place in parallel. From time to time these activities may have to be synchronized. This is, for instance, the case when two or more travel agents try to book the same seat on the same flight. A computerized model must be able to represent the synchronization of activities.

A number of activities may be viewed as compound systems consisting of parallel concurrent activities. Examples of this are machines consisting of several parts, each executing an independent activity. In other cases an activity A may be characterized by performing several other activities, but at most one at a time. The activity A will then shift between these other activities. An example of this is a cook making dishes. This involves several ongoing activities by the cook who constantly shifts between those requiring his/her attention. Another example is the agents of a travel agency. They often perform complex tasks consisting of several more or less independent activities. An agent may be involved in ‘tour planning,’ ‘customer service’ and ‘invoicing.’ The agent will alternate between these activities. When an agent shifts to a new activity, the current activity is temporarily suspended. Later when the agent returns to this activity it is resumed at the the point of suspension. This form of sequencing is called alternation.

Alternation should not be confused with true concurrency, where a number of tasks take place at the same time. In alternation, at most one of the tasks takes place at a given time. We return to alternation in chapter .