Chapter 6 - Behavioural Modelling
Chapter 6 - Behavioural Modelling
Chapter 6 - Behavioural Modelling
Chapter 6
ITOOA3-B11
Objectives
• Understand the rules and style guidelines for sequence and
behavioural state machines.
• Understand the processes used to create sequence, behavioural
state machines and CRUDE matrices.
• Be able to create sequence and behavioural state machines.
• Understand the relationship between the behavioural models and
the structural and functional models.
2
Introduction
• In this chapter, we discuss how analysts use behavioural models
to represent the internal behaviour or dynamic view of an
information system.
There are two types of behavioural models:
1. Sequence diagrams – model the distribution of the behaviour
of the system over the actors and objects in the system. In this
way, we can easily see how actors and objects collaborate to
provide the functionality defined in a use case.
2. Behavioural state machines – represent the changes that occur
in the underlying data.
3
Behavioural Models
• Traditionally, behavioural models have been used primarily during
design, where analysts refine the behavioural models to include
implementation details. For now, our focus is on what the
dynamic view of the evolving system is and not on how the
dynamic aspect of the system will be implemented.
• Finally, we describe CRUDE analysis and the process to verify and
validate the behavioural models.
4
Interaction Diagrams
• One of the primary differences between class diagrams and
interaction diagrams, besides the obvious difference that one
describes structure and the other behaviour, is that the modelling
focus on a class diagram is at the class level, whereas the
interaction diagrams focus on the object level.
• In this section, we review objects, operations, and messages.
5
Objects, Operations, and Messages
• An object is an instantiation of a class, i.e., an actual person,
place, or thing about which we want to capture information. If
we were building an appointment system for a doctor’s office,
classes might include doctor, patient, and appointment. The
specific patients, such as Jim Maloney, Mary Wilson, and Theresa
Marks, are considered objects—i.e., instances of the patient
class.
• Each object has attributes that describe information about the
object, such as a patient’s name, birth date, address, and phone
number. Each object also has behaviours. At this point in the
development of the evolving system, the behaviours are
described by operations. An operation is nothing more than an
action that an object can perform. For example, an appointment
object can probably schedule a new appointment, delete an
appointment, and locate the next available appointment. Later
on during the development of the evolving system, the
behaviours will be implemented as methods.
6
• Each object also can send and receive messages. Messages are
information sent to objects to tell an object to execute one of its
behaviours. Essentially, a message is a function or procedure call
from one object to another object. For example, if a patient is
new to the doctor’s office, the system sends an insert message to
the application. The patient object receives the instruction (the
message) and does what it needs to do to insert the new patient
into the system (the behaviour).
7
Sequence Diagrams
• Sequence diagrams illustrate the objects that participate in a use
case and the messages that pass between them over time for one use
case. A sequence diagram is a dynamic model that shows the
explicit sequence of messages that are passed between objects in a
defined interaction. Because sequence diagrams emphasize the
time-based ordering of the activity that takes place among a set of
objects, they are very helpful for understanding real-time
specifications and complex use cases.
• The sequence diagram can be a generic sequence diagram that
shows all possible scenarios for a use case, but usually each analyst
develops a set of instance sequence diagrams, each of which depicts
a single scenario within the use case. If you are interested in
understanding the flow of control of a scenario by time, you should
use a sequence diagram to depict this information.
8
Elements of a Sequence Diagram
9
10
11
12
13
Guidelines for Creating Sequence Diagrams
Ambler provides a set of guidelines when drawing sequence diagrams:
• Try to have the messages not only in a top-to-bottom order but also, when
possible, in a left -to-right order. To accomplish this, order the actors and
objects along the top of the diagram in the order that they participate in
the scenario of the use case.
• If an actor and an object conceptually represent the same idea, one inside
of the software and the other outside, label them with the same name.
• The initiator of the scenario—actor or object—should be drawn as the
farthest left item in the diagram.
• When there are multiple objects of the same type, be sure to include a
name for the object in addition to the class of the object.
• Show return values only when they are not obvious.
• Justify message names and return values near the arrowhead of the
message and return arrows, respectively. This makes it much easier to
interpret the messages and their return values.
14
Creating Sequence Diagrams
A six-step process used to create a sequence diagram:
1. Set Context
2. Identify Actors and Objects
3. Set Lifeline
4. Add Messages
5. Place Execution Occurrence
6. Validate
15
Campus Housing Example
16
Library Example
17
18
Behavioural State Machines
• Some of the classes in the class diagrams represent a set of objects
that are quite dynamic in that they pass through a variety of states
over the course of their existence. For example, a patient can
change over time from being new to current to former based on his
or her status with the doctor’s office. A behavioural state machine
is a dynamic model that shows the different states through which a
single object passes during its life in response to events, along with
its responses and actions.
• Typically, behavioural state machines are not used for all objects;
rather, behavioural state machines are used with complex objects to
further define them and to help simplify the design of algorithms for
their methods. The behavioural state machine shows the different
states of the object and what events cause the object to change from
one state to another. Behavioural state machines should be used to
help understand the dynamic aspects of a single class and how its
instances evolve over time.
19
States, Events, Transitions, Actions, and Activities
• The state of an object is defined by the value of its attributes and its
relationships with other objects at a particular point in time. For
example, a patient might have a state of new, current, or former. The
attributes or properties of an object affect the state that it is in;
however, not all attributes or attribute changes will make a difference.
For example, think about a patient’s address. Those attributes make
very little difference to changes in a patient’s state. However, if states
were based on a patient’s geographic location (e.g., in-town patients
were treated differently than out-of-town patients), changes to the
patient’s address would influence state changes.
• An event is something that takes place at a certain point in time and
changes a value or values that describe an object, which, in turn,
changes the object’s state. It can be a designated condition becoming
true, the receipt of the call for a method by an object, or the passage of
a designated period of time. The state of the object determines exactly
what the response will be.
20
• A transition is a relationship that represents the movement of an
object from one state to another state. Some transitions have a guard
condition. A guard condition is a Boolean expression that includes
attribute values, which allows a transition to occur only if the condition
is true. An object typically moves from one state to another based on
the outcome of an action triggered by an event.
21
Elements of a Behavioural State Machine
22
23
24
Guidelines for Creating Behavioural State Machines
Ambler provides a set of guidelines when drawing state machines:
• Create a behavioural state machine for objects whose behaviour changes
based on the state of the object. In other words, do not create a behavioural
state machine for an object whose behaviour is always the same regardless of
its state. These objects are too simple.
• To adhere to the left -to-right and top-to-bottom reading conventions of
Western cultures, the initial state should be drawn in the top left corner of the
diagram and the final state should be drawn in the bottom right of the diagram.
• Make sure that the names of the states are simple, intuitively obvious, and
descriptive.
• Question black hole and miracle states. These types of states are problematic
for the same reason black hole and miracle activities are a problem for activity
diagrams. Black hole states, states that an object goes into and never comes
out of, most likely are actually final states. Miracle states, states that an object
comes out of but never went into, most likely are initial states.
• Be sure that all guard conditions are mutually exclusive (not overlapping).
• All transitions should be associated with a message and operation. Otherwise,
the state of the object could never change.
25
Creating a Behavioural State Machine
A five-step process used to create a state machine:
1. Set Context
2. Identify Object States
3. Lay Out Diagram
4. Add Transitions
5. Validate
26
Campus Housing Example
27
Library Example
28
CRUDE Analysis
• One useful technique to identify how the underlying objects in the
problem domain work together to collaborate in support of the use
cases is CRUDE analysis.
• CRUDE analysis uses a CRUDE matrix, in which each interaction
among objects is labelled with a letter for the type of interaction:
C for create, R for read or reference, U for update, D for delete, and
E for execute.
• In an object-oriented approach, a class/actor-by-class/actor matrix is
used. Each cell in the matrix represents the interaction between
instances of the classes.
29
30
Campus Housing Example
31
Library Example
32
Verifying & Validating the Behavioural
Model
• First, all transitions contained in a behaviour state machine must be
associated with a message being sent on a sequence diagram, and it
must be classified as a (C)reate, (U)pdate, or (D)elete message in a
CRUDE matrix.
• Second, all entries in a CRUDE matrix imply a message being sent
from an actor or object to another actor or object. If the entry is a
(C)reate, (U)pdate, or (D)elete and the execution of the related
operation changes the state of the object, then there must be an
associated transition in a behavioural state machine that represents
the instances of the receiving class.
33
Additional Example
ClearSkin provides skin treatments and skin products to customers.
Clients come into the store to speak to a skin consultant to find the
relevant treatments and/or products. The consultant makes a booking
and/or order products on the system for the client.
ClearSkin would like an online system where the client can read up on
the products and/or treatments on their own time. They need to be
able to book a session directly on the online system and order
products. Clients will be able to find the store closest to their current
location. If they have any questions, they can direct them to an online
consultant.
The system will check if the client is allergic to any of the product
ingredients. If they are allergic, the order will be cancelled. Otherwise,
they will be directed to the online payment section. A final
confirmation will be sent when all the steps are completed.
Create an instance sequence diagram for ordering a product
successfully. Include the return messages.
34
Solution
35
Exercise
Study the scenario and draw a sequence diagram for a vehicle
owner that would like to renew their vehicle registration.
An organization has been entrusted with developing a Registration
and Title system that maintains information about all vehicles
registered in a particular province. For each vehicle that is
registered with the office, the system must store the name,
address, telephone number of the owner, the start date and end
date of the registration, plate information, sticker and registration
fee. In addition, the following information is maintained about the
vehicles themselves: the number, year, make, model, body, gross
weight, number of passengers, colour and kilometers. The system
issues registration notices to owners of vehicles whose registrations
are due to expire after two months. When the owner renews the
registration, the system updates the registration information on the
vehicle.
Adjusted from Source: Valacich, J.S., George, J.F. & Hoffer, J.A. 2015. Essentials of systems analysis
and design. 6th ed. Pearson: London. p 413.
36
Solution
37
Exercises
For the online university registration system problem in Chapters 4
(exercises G).
1. Create a sequence diagram for a student to add a course
successfully to their schedule.
2. Draw a state diagram to show the possible states that a student
can be in.
38
Solution 1
39
Solution 2
40
Exercises
For the gym membership problem in Chapters 4 (exercises O).
1. Create a sequence diagram for the updating and sending a
renewal request.
2. Draw a state diagram to show the possible states that a
member can be in.
41
Summary
• Understand the rules and style guidelines for sequence and
behavioural state machines.
• Understand the processes used to create sequence, behavioural
state machines and CRUDE matrices.
• Be able to create sequence and behavioural state machines.
• Understand the relationship between the behavioural models and
the structural and functional models.
42