You are on page 1of 27

SYSTEM

BEHAVIOR
Dr. Salome Maro
16th May 2022
SYSTEM BEHAVIOR
 All systems have static structure and dynamic behavior;
 Class diagrams are best used to document and express the static structure of a
system
 Objects within systems communicate with each other; they send messages to
each other.
 Describing the static structure of a system can reveal what the system contains
and how those things are related, but it does not explain how these things
cooperate to manage their tasks and provide the functionality of the system.
SYSTEM BEHAVIOR
 UML gives 3 diagrams to model system behaviour:
 State machines
 Activity diagrams
 Interaction diagrams
SYSTEM BEHAVIOR
 State Machines: These describe which states an object can have during its life
cycle, and the behavior in those states along with what events cause the state to
change;
 for example, an invoice can be paid (state paid) or unpaid (state unpaid).
 Activity diagrams: show communication in a system, but they focus on
workflow.
 Interactions diagrams: describe how objects communicate with each other.
How and which messages and sent and received.
SYSTEM BEHAVIOR
 Interaction and activity diagrams both show communication between objects
 Interaction diagrams focus on the collaboration among the objects
 Activity diagrams focus on set of actions occurring in a workflow

 Choice depends on which aspect is considered the most important


USE CASES, CLASS DIAGRAMS
AND STATE MACHINES
 Use cases – describes the interaction of actors with different functionalities of
the system

 Class diagrams – Describe the structure of the system and are used in the
implementation of the use cases

 State machines – Describes the state of the objects modelled in the class
diagrams
STATE MACHINES
 All objects have a state
 Examples of object states are:
 The invoice (object) is paid (state).
 The car (object) is standing still (state).
 The engine (object) is running (state).
 Kate (object) is married (state).
STATE MACHINES
 An object transitions (changes) from one state to another state when
something happens, which is called an event;

 A state machine diagram models the behavior of a single object, specifying


the sequence of events that an object goes through during its lifetime in
response to events.
STATE MACHINES
 Example: A door

 The door can be in one of three states: "Opened", "Closed" or "Locked".


STATE MACHINES
 Example: A door

 The door can be in one of three states: "Opened", "Closed" or "Locked".


STATE MACHINE DIAGRAMS
 It can respond to the events Open, Close, Lock
and Unlock. Notice that not all events are
valid in all states; for example, if a door is
opened, you cannot lock it until you close it.

 Also notice that a state transition can have a


guard condition attached: if the door is
Opened, it can only respond to the Close event
if the condition doorway->isEmpty
is fulfilled.
STATE MACHINE DIAGRAMS
 States - A state is denoted by a round-cornered rectangle with the name of the
state written inside it.

 Initial and Final States - The initial state is denoted by a filled black circle
and may be labeled with a name. The final state is denoted by a circle with a
dot inside and may also be labeled with a name.
STATE MACHINE DIAGRAMS
• Transitions - Transitions from one state to
the next are denoted by lines with
arrowheads.

• Self-Transitions - A state can have a Self-transition


transition that returns to itself.

State A
STATE MACHINE DIAGRAMS
 A transition may have a trigger, a guard and an effect.
 "Trigger" is the cause of the transition, which could be a signal, an event, a change in
some condition, or the passage of time. Example: Request received

 "Guard" is a condition which must be true in order for the trigger to cause the
transition. Example: [t = 15sec], [number of invoices > n], withdrawal (amount)
[balance >= amount]

 "Effect" is an action which will be invoked directly on the object that owns the state
machine as a result of the transition. Example: Send request or approve request
STATE MACHINES DIAGRAMS

Effect
STATE MACHINE DIAGRAMS
• State Actions - In the transition example above, an effect was associated with the transition. If the
target state had many transitions arriving at it, and each transition had the same effect associated
with it, it would be better to associate the effect with the target state rather than the transitions.

• This can be done by defining an entry action for the state.

• It is also possible to define actions that occur on events, or actions that always occur. It is
possible to define any number of actions of each type.

Verify card

Entry/ receive card


Do/ check if card is valid
Exit/ Inform cust.
STATE MACHINE DIAGRAMS
 Compound States - A state machine diagram may include sub-machine diagrams.
STATE MACHINE DIAGRAMS

 Choice Pseudo-State - A choice pseudo-state is shown as a diamond with one transition


arriving and two or more transitions leaving. The following diagram shows that whichever
state is arrived at, after the choice pseudo-state, is dependent on the message format selected
during execution of the previous state.
EXAMPLES
The elevator starts at the first floor. It can be moving up or moving
down. If the elevator is idle on one floor, a time-out event occurs
after a period and moves the elevator back to the first floor.
EXAMPLES
The elevator starts at the first floor. It can be moving up or moving
down. If the elevator is idle on one floor, a time-out event occurs
after a period and moves the elevator back to the first floor.
A STATE MACHINE DIAGRAM FOR
AN ELEVATOR.
A STATE MACHINE DIAGRAM FOR
AN ELEVATOR. – ADD ACTIONS
A STATE MACHINE DIAGRAM
FOR AN ELEVATOR. – ADD
GUARDS
A STATE MACHINE DIAGRAM
FOR AN ELEVATOR. – ADD
EFFECT
EXAMPLE – A WATCH
 The watch has three states: its normal display state showing the time, and two states for setting
clock (hours and minutes, respectively). Whenever you press the mode button, you switch
from one state to another.
NEXT WEEK: TEST 1
 Test 1 will be on Thursday 26th May.

 Test coverage: Lecture 1 to 5

 Test will be online (LMS)


QUESTIONS?

You might also like