You are on page 1of 19

UML-STATE MACHINE & SEQUENCE

DIAGRAM
CUONG V. NGUYEN - SE 2020 1
AGENDA
▪ State machine diagram
▪ Sequence diagram

CUONG V. NGUYEN - SE 2020 2


STATE MACHINE DIAGRAM
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:
▪ A state is an abstraction of the attribute values and links of an object. Sets
of values are grouped together into a state according to properties that
affect the gross behavior of the object.
▪ A state machine diagram is a graph consisting of:
 States (simple states or composite states)
 Transitions connecting the states

CUONG V. NGUYEN - SE 2020 3


TYPE OF STATES
▪ States : stable, can only be transited by an event
▪ Pseudo-states: abstraction of different forms of transitive state, can be
changed through an execution

CUONG V. NGUYEN - SE 2020 4


EXAMPLE

CUONG V. NGUYEN - SE 2020 5


EVENTS
▪ Represents incidents that cause objects to transition from one state to
another.
▪ Internal or External Events trigger some activity that changes the state of the
system and of some of its parts
▪ Events pass information, which is elaborated by Objects operations. Objects
realize Events
▪ Design involves examining events in a state machine diagram and
considering how those events will be supported by system objects

CUONG V. NGUYEN - SE 2020 6


TRANSITION
▪ Transition lines depict the movement from one state to another. Each transition line is
labeled with the event that causes the transition. Understanding state transitions is
part of system analysis and design
▪ Transitions between states occur as follows:
 An element is in a source state
 An event occurs
 An action is performed
 The element enters a target state
▪ Multiple transitions occur either when different events result in a state terminating
or when there are guard conditions on the transitions
▪ A transition without an event and action is known as automatic transitions

CUONG V. NGUYEN - SE 2020 7


LET’S CREATE ONE

CUONG V. NGUYEN - SE 2020 8


SEQUENCE DIAGRAM
▪ A sequence diagram shows object interactions arranged in time sequence. It
depicts the objects and classes involved in the scenario and the sequence of
messages exchanged between the objects needed to carry out the
functionality of the scenario
▪ A sequence diagram is a good way to visualize and validate various
runtime scenarios. These can help to predict how a system will behave and
to discover responsibilities a class may need to have in the process of
modeling a new system.

CUONG V. NGUYEN - SE 2020 10


NOTATIONS
Actor
▪ a type of role played by an entity that interacts
with the subject (e.g., by exchanging signals and
data)
▪ external to the subject (i.e., in the sense that an
instance of an actor is not a part of the instance
of its corresponding subject).
▪ represent roles played by human users, external
hardware, or other subjects.

CUONG V. NGUYEN - SE 2020 11


LIFELINE
Lifeline:
▪ A lifeline represents an individual participant in the interaction.
▪ A lifeline always portrays an object internal to the system whereas actors
are used to depict objects external to the system.

CUONG V. NGUYEN - SE 2020 12


ACTIVATION BARS
▪ Activation bar is the box placed on the lifeline.
▪ It is used to indicate that an object is active (or instantiated) during an
interaction between two objects.
▪ The length of the rectangle indicates the duration of the objects staying
active.

CUONG V. NGUYEN - SE 2020 13


MESSAGES
▪ An arrow from the Message Caller to the Message Receiver specifies a
message in a sequence diagram.
▪ Synchronous message: sender waits for the receiver to process the
message and return before continue with another message. Identified by a
solid arrowhead.

▪ Asynchronous message: sender does not wait for the receiver to process
the message, concurrently sends other messages to other.

CUONG V. NGUYEN - SE 2020 14


MESSAGES
▪ Return message: indicate that the message receiver is done processing the
message and is returning control over to the message caller.

▪ Reflexive message: object sends a message to itself.

CUONG V. NGUYEN - SE 2020 15


MESSAGES
▪ Delete Message: used to delete an object. When an object is deallocated
memory or is destroyed within the system we use the Delete Message
symbol. It destroys the occurrence of the object in the system. It is
represented by an arrow terminating with a x.

▪ Creation message: Objects or participants can be created later in the flow


by sending a message.

CUONG V. NGUYEN - SE 2020 16


DIMENSIONS
Component Dimension: Time Dimension:
▪ The horizontal axis shows the ▪ The vertical axis represents time
elements that are involved in the proceedings (or progressing) down
interaction the page.
▪ Conventionally, the objects involved ▪ Time in a sequence diagram is all a
in the operation are listed from left about ordering, not duration.
to right according to when they
take part in the message sequence. ▪ The vertical space in an interaction
diagram is not relevant for the
duration of the interaction.

CUONG V. NGUYEN - SE 2020 17


FLOW
▪ A sequence diagram is structured in such a way that it represents a timeline
which begins at the top and descends gradually to mark the sequence of
interactions.
▪ In this flow, different parts of a system work in a ‘sequence’ to get something
done.
▪ Sequence diagrams describe in what order the objects in a system operate
to achieve the goal.

CUONG V. NGUYEN - SE 2020 18


ALTERNATIVES
▪ Alternative fragment: used when a choice needs to be made between two
or more message sequences. It models the “if then else” logic.

▪ Optional fragment: the fragment executes only if the supplied condition is


true. Equivalent to an alt only with one trace.

CUONG V. NGUYEN - SE 2020 19


SUMMARY
▪ State diagrams describe behavior of a system mainly by depicting states
and transitions
▪ A sequence diagram is a type of interaction diagram, it describes how and
in what order a group of objects works together.
▪ A state machine diagram describes all events (and states and transitions for
a single object)
▪ A sequence diagram describes the events for a single interaction across all
objects involved

CUONG V. NGUYEN - SE 2020 21

You might also like