0% found this document useful (0 votes)
44 views

Sequence Diagrams

The document provides an overview of interaction diagrams in UML, including: - The four main types of interaction diagrams: sequence diagrams, communication diagrams, timing diagrams, and interaction overview diagrams. - How interaction diagrams describe object interactions and message exchanges. - Notations for lifelines, messages, synchronous/asynchronous messages, and other elements. - Examples of how to model object creation, destruction, and execution specifications.

Uploaded by

Anas Assoufi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views

Sequence Diagrams

The document provides an overview of interaction diagrams in UML, including: - The four main types of interaction diagrams: sequence diagrams, communication diagrams, timing diagrams, and interaction overview diagrams. - How interaction diagrams describe object interactions and message exchanges. - Notations for lifelines, messages, synchronous/asynchronous messages, and other elements. - Examples of how to model object creation, destruction, and execution specifications.

Uploaded by

Anas Assoufi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 70

2IX20 Software Specification

INTERACTION DIAGRAMS

Based on the slides provided by M.Seidl,


M.Scholz, C. Huemer and G.Kappel,
authors of the book UML@Classroom
Under the Creative Commons Attribution-
NonCommercial 4.0 International licence.
See http://www.uml.ac.at/en/lernen.

Jeroen Keiren

Mathematics & Computer Science / Formal System Analysis


Bug: ChatGPT spewing nonsense

- Optimization to user
experience -> bug
language processing
- Bug in choosing numbers
that map to tokens
- Lead to sentences that
make no sense
- “Inference kernels
produced incorrect results
when used in certain GPU
configurations”
https://www.reddit.com/r/ChatGPT/comments/1avwqzh/very_strange_rambling_responses/
https://status.openai.com/incidents/ssg8fh7sfyz3

2 2IX20 Interaction diagrams


Exercise

3 2IX20 Interaction diagrams


Interaction Diagrams

Diagram

Structure Behavior
Diagram Diagram

Class Package Profile Object Activity State Machine Interaction Use Case
Diagram Diagram Diagram Diagram Diagram Diagram Diagram Diagram

Deployment Composition Component Sequence Communication Interaction Timing


Diagram Structure Diagram Diagram Diagram Overview Diagram
Diagram Diagram

4 2IX20 Interaction diagrams


Interaction diagrams: missing link

• Use case diagram describes tasks that system must help actors to
perform
• Class diagram describes classes required to realize use cases and
relationships between these classes
• Interaction diagrams describe how objects interact to realize the use
case scenarios
• Interaction diagrams should be consistent with the corresponding
class diagrams and use case diagrams

5 2IX20 Interaction diagrams


Introduction

• Modeling inter-object behavior


= interactions between objects
• Interaction
• Specifies how messages and data are exchanged between interaction partners
• Interaction partners
• Human (lecturer, administrator, …)
• Non-human (server, printer, executable software, …)
• Examples of interactions
• Conversation between persons
• Message exchange between humans and a software system
• Communication protocols
• Sequence of method calls in a program
• …

6 2IX20 Interaction diagrams


Four Types of Interaction Diagrams (1/4)

• Based on the same concepts


• Generally equivalent for simple interactions, but different focus

Sequence diagram
• Vertical axis:
• chronological order
• Horizontal axis:
• interaction partners

7 2IX20 Interaction diagrams


Four Types of Interaction Diagrams (2/4)

Communication diagram
• Models the relationships between communication partners
• Focus: Who communicates with whom
• Time is not a separate dimension
• Message order via decimal classification

8 2IX20 Interaction diagrams


Four Types of Interaction Diagrams (3/4)

Timing diagram
• Shows state changes of the
interaction partners that result from
the occurrence of events
• Vertical axis: interaction partners
• Horizontal axis: chronological order

9 2IX20 Interaction diagrams


Four Types of Interaction Diagrams (4/4)
Interaction overview diagram
• Visualizes order of different interactions
• Allows to place various interaction diagrams in a logical order
• Basic notation concepts of activity diagram

10 2IX20 Interaction diagrams


Interaction Diagrams

• Used to specify interactions


• Modeling concrete scenarios
• Describing communication sequences at different levels of detail

• Interaction Diagrams show the following:


• Interaction of a system with its environment
• Interaction between system parts in order to show how a specific use case can be
implemented
• Interprocess communication in which the partners involved must observe certain
protocols
• Communication at class level (operation calls, inter-object behavior)

11 2IX20 Interaction diagrams


Overview

Diagram

Structure Behavior
Diagram Diagram

Class Package Profile Object Activity State Machine Interaction Use Case
Diagram Diagram Diagram Diagram Diagram Diagram Diagram Diagram

Deployment Composition Component Sequence Communication Interaction Timing


Diagram Structure Diagram Diagram Diagram Overview Diagram
Diagram Diagram

12 2IX20 Interaction diagrams


Interaction partners and lifelines

13 2IX20 Interaction diagrams


Sequence Diagram

• Two-dimensional diagram
• Horizontal axis: involved interaction partners
• Vertical axis: chronological order of the
interaction
• Interaction = sequence of event
specifications

14 2IX20 UML Sequence diagrams


Interaction Partners
• Interaction partners are depicted as lifelines
• Head of the lifeline
• Rectangle that contains the expression roleName:Class
• Roles are a more general concept than objects
• Object can take on different roles over its lifetime
• Body of the lifeline
• Vertical, usually dashed line
• Represents the lifetime of the object associated with it
Head of the lifeline

Body of the Lifeline

15 2IX20 UML Sequence diagrams


Interaction Partners: Notation

Object Actor

16 2IX20 UML Sequence diagrams


Creation and destruction

• Object creation
• Dashed arrow
• Arrowhead points to the head of the
lifeline of the object to be created
• Keyword new

• Object destruction
• Object is deleted
• Large cross (×) at the end of the lifeline

17 2IX20 UML Sequence diagrams


Message exchange

• Synchronous
• Asynchronous
• Response

• Found and lost messages


• Time consuming messages

18 2IX20 Interaction diagrams


Exchanging Messages (1/2)

• Interaction: sequence of events


• Message is defined via send event
and receive event Send event
Receive event

Execution specification
• Execution specification
• Continuous bar
• Used to visualize when an interaction
partner executes some behavior

19 2IX20 UML Sequence diagrams


Exchanging Messages (2/2)

Order of messages:

… on one lifeline … on different lifelines … on different lifelines


which exchange messages

»Happens before«

20 2IX20 UML Sequence diagrams


Synchronous messages

• Synchronous message
• Sender waits until it has received a response message
before continuing
• Syntax of message name: msg(par1,par2)
• msg: the name of the message
• par: parameters separated by commas

21 2IX20 UML Sequence diagrams


Asynchronous messages

• Asynchronous message
• Sender continues without waiting for a response message
• Syntax of message name: msg(par1,par2)

22 2IX20 UML Sequence diagrams


Response messages

• Response message
• May be omitted if content and location are obvious
• Syntax: att=msg(par1,par2):val
• att: the return value can optionally be assigned to a variable
• msg: the name of the message
• par: parameters separated by commas
• val: return value

23 2IX20 UML Sequence diagrams


Found and lost messages

• Found message
• Sender of a message is unknown or not relevant
• Lost message
• Receiver of a message is unknown or not relevant

24 2IX20 UML Sequence diagrams


Time consuming messages

• Time-consuming message
• "Message with duration”
• Usually messages are assumed to be transmitted without any loss of time
• Express that time elapses between the sending and the receipt of a message

25 2IX20 UML Sequence diagrams


Notation Elements (1/2)
Name Notation Description

Interaction partners involved in


Lifeline the communication

Time at which an interaction partner


Destruction event
ceases to exist

26 2IX20 UML Sequence diagrams


Notation Elements (2/2)
Name Notation Description
Synchronous
Sender waits for a response message
message

Response message Response to a synchronous message

Sender continues its own work


Asynchronous
after sending the asynchronous
communication
message

Lost message Message to an unknown receiver

Message from an unknown


Found message
sender

27 2IX20 UML Sequence diagrams


Combined fragments

• Branches and loops


• Concurrency and order
• Filters and assertions

28 2IX20 Interaction diagrams


Combined Fragments

• Model various control structures


• 12 predefined types of operators
Combined Fragment

Operator
Operand

Operand
Operand

29 2IX20 UML Sequence diagrams: combined fragments – branches and loops


Types of Combined Fragments
Operator Purpose
Branches and alt Alternative interaction

opt Optional interaction


loops

loop Repeated interaction

break Exception interaction

seq Weak order


Concurrency
and order

strict Strict order

par Concurrent interaction

critical Atomic interaction

ignore Irrelevant interaction


Filters and
assertions

consider Relevant interaction

assert Asserted interaction

neg Invalid interaction

30 2IX20 UML Sequence diagrams: combined fragments – branches and loops


Combined Fragments: Branches and Loops
Operator Purpose
Branches and alt Alternative interaction

opt Optional interaction


loops

loop Repeated interaction

break Exception interaction

seq Weak order


Concurrency
and order

strict Strict order

par Concurrent interaction

critical Atomic interaction

ignore Irrelevant interaction


Filters and
assertions

consider Relevant interaction

assert Asserted interaction

neg Invalid interaction

31 2IX20 UML Sequence diagrams: combined fragments – branches and loops


alt Fragment

• To model alternative sequences


• Similar to switch statement in Java
• Guards are used to select the one path to be
executed
• Guards
• Modeled in square brackets
• default: true
• predefined: [else]

• Multiple operands
• Guards have to be disjoint to avoid
nondeterministic behavior

32 2IX20 UML Sequence diagrams: combined fragments – branches and loops


opt Fragment

• To model an optional sequence


• Actual execution at runtime is dependent
on the guard
• Exactly one operand
• Similar to if statement without else
branch
• equivalent to alt fragment with two
operands, one of which is empty

33 2IX20 UML Sequence diagrams: combined fragments – branches and loops


loop Fragment

• To express that a sequence is to be executed repeatedly


• Exactly one operand
• Keyword loop followed by the minimal/maximal number of iterations
(min..max) or (min,max)
• default: (*) .. no lower/upper limit
• Guard
• Evaluated as soon as the minimum number of iterations has taken place
• Checked for each iteration within the (min,max) limits
• If the guard evaluates to false, the execution of the loop is terminated

34 2IX20 UML Sequence diagrams: combined fragments – branches and loops


loop Fragment - Example

• Keyword loop followed by the minimal/maximal number of iterations


(min..max) or (min,max)

Max
Min
Guard
Notation alternatives:

loop is executed at loop(3,8) = loop(3..8)


least once, then as long loop(8,8) = loop (8)
as a<1 is true loop = loop (*) = loop(0,*)

35 2IX20 UML Sequence diagrams: combined fragments – branches and loops


break Fragment

• Simple form of exception handling


• Exactly one operand with a guard
• If the guard is true:
• Interactions within this operand are executed
• Remaining operations of the surrounding
fragment are omitted
• Interaction continues in the next higher level
fragment
• Different behavior compared to opt Not executed if
fragment break is executed

36 2IX20 UML Sequence diagrams: combined fragments – branches and loops


loop and break Fragment - Example

37 2IX20 UML Sequence diagrams: combined fragments – branches and loops


Combined Fragments: Concurrency and Order
Operator Purpose
Branches and alt Alternative interaction

opt Optional interaction


loops

loop Repeated interaction

break Exception interaction

seq Weak order


Concurrency
and order

strict Strict order

par Concurrent interaction

critical Atomic interaction

ignore Irrelevant interaction


Filters and
assertions

consider Relevant interaction

assert Asserted interaction

neg Invalid interaction

38 2IX20 UML Sequence diagrams: combined fragments – concurrency and order


seq Fragment

• Default order of events


• Weak sequencing:
1. The ordering of events within each of the operands is
maintained in the result
2. Events on different lifelines from different operands may
come in any order
3. Events on the same lifeline from different operands are
ordered such that an event of the first operand comes
before that of the second operand

39 2IX20 UML Sequence diagrams: combined fragments – concurrency and order


seq Fragment – Example

40 2IX20 UML Sequence diagrams: combined fragments – concurrency and order


strict Fragment

• Sequential interaction with order


• Order of event occurrences on different lifelines
between different operands is significant
• Messages in an operand that is higher up on the vertical
axis are always exchanged before the messages in an
operand that is lower down on the vertical axis

41 2IX20 UML Sequence diagrams: combined fragments – concurrency and order


strict Fragment - Example

42 2IX20 UML Sequence diagrams: combined fragments – concurrency and order


par Fragment

• To set aside chronological order between messages


in different operands
• Execution paths of different operands can be
interleaved
• Restrictions of each operand need to be respected
• Order of the different operands is irrelevant
• Concurrency, no true parallelism

43 2IX20 UML Sequence diagrams: combined fragments – concurrency and order


par Fragment - Example

44 2IX20 UML Sequence diagrams: combined fragments – concurrency and order


Coregion

• To model concurrent events of a single


lifeline
• Order of event occurrences within a Impact of
coregion is not restricted coregion
• Area of the lifeline to be covered by the Coregion
coregion is marked by square brackets
rotated by 90 degrees

45 2IX20 UML Sequence diagrams: combined fragments – concurrency and order


Coregion – Example

46 2IX20 UML Sequence diagrams: combined fragments – concurrency and order


critical Fragment

• Atomic area in the interaction (one operand)


• To make sure that certain parts of an interaction
are not interrupted by unexpected events
• Order within critical: default order seq

47 2IX20 UML Sequence diagrams: combined fragments – concurrency and order


critical Fragment - Example

48 2IX20 UML Sequence diagrams: combined fragments – concurrency and order


Combined Fragments: Filters and Assertions
Operator Purpose
Branches and alt Alternative interaction

opt Optional interaction


loops

loop Repeated interaction

break Exception interaction

seq Weak order


Concurrency
and order

strict Strict order

par Concurrent interaction

critical Atomic interaction

ignore Irrelevant interaction


Filters and
assertions

consider Relevant interaction

assert Asserted interaction

neg Invalid interaction

49 2IX20 UML Sequence diagrams: combined fragments – filters and assertions


ignore Fragment

• To indicate irrelevant messages


• Messages may occur at runtime but have no
further significance
• Exactly one operand
• Irrelevant messages in curly brackets after the
keyword ignore

50 2IX20 UML Sequence diagrams: combined fragments – filters and assertions


consider Fragment

• To specify those messages that are of particular


importance for the interaction under consideration
• Exactly one operand, dual to ignore fragment
• Considered messages in curly brackets after the
keyword consider

51 2IX20 UML Sequence diagrams: combined fragments – filters and assertions


ignore vs. consider

52 2IX20 UML Sequence diagrams: combined fragments – filters and assertions


assert Fragment

• To identify certain modeled traces as mandatory


• Deviations that occur in reality but that are not
included in the diagram are not permitted
• Exactly one operand

53 2IX20 UML Sequence diagrams: combined fragments – filters and assertions


neg Fragment

• To model invalid interactions


• Describing situations that must not occur
• Exactly one operand
• Purpose
• Explicitly highlighting frequently occurring errors
• Depicting relevant, incorrect sequences

54 2IX20 UML Sequence diagrams: combined fragments – filters and assertions


Notation Elements
Name Notation Description

Combined
Control constructs
fragment

55 2IX20 UML Sequence diagrams: combined fragments – filters and assertions


Types of Combined Fragments
Operator Purpose
Branches and alt Alternative interaction

opt Optional interaction


loops

loop Repeated interaction

break Exception interaction

seq Weak order


Concurrency
and order

strict Strict order

par Concurrent interaction

critical Atomic interaction

ignore Irrelevant interaction


Filters and
assertions

consider Relevant interaction

assert Asserted interaction

neg Invalid interaction

56 2IX20 UML Sequence diagrams: combined fragments – filters and assertions


Building sequence diagrams

57 2IX20 Interaction diagrams


How to build sequence diagrams?

• Set context
• Identify participants that should interact to realize the use-case
scenario / to respond to messages arriving at the interface
• Set lifeline for each participant
• Add messages by drawing arrows
• Order messages from left to right, top to bottom
• Show how they are passed from one object to another
• Add activations to each participant’s lifeline
• Validate the sequence diagram

58 2IX20 UML Sequence diagrams: construction and validation


Interaction Reference

• Integrates one sequence diagram in another sequence diagram

59 2IX20 UML Sequence diagrams: construction and validation


Gate

• Allows you to send and receive messages beyond the boundaries of the
interaction fragment

60 2IX20 UML Sequence diagrams: construction and validation


Continuation Marker

• Modularizes the operands of an alt fragment

Target
marker
Start
marker

61 2IX20 UML Sequence diagrams: construction and validation


Continuation Marker

• Modularizes the operands of an alt fragment


• Breaks down complex interactions into parts and connect them to one
another with markers
• Start marker points to target marker
• No return to the start marker (in contrast to an interaction reference)

62 2IX20 UML Sequence diagrams: construction and validation


Local Attributes and Parameters

• Every sequence diagram is enclosed by a rectangular frame with a small


pentagon in the upper left corner
• Keyword sd, name of the sequence diagram, parameters (optional)
• Example: void func (int par1, int par2) {
int x = 0;
String y = "Test";
...
}

Option 1: Parameter Option 2:

Local
attributes

63 2IX20 UML Sequence diagrams: construction and validation


Time Constraints

• Types
• Point in time for event occurrence
• Relative: e.g., after(5sec)
• Absolute: e.g., at(12.00)
• Time period between two events
• {lower..upper}
• E.g., {12.00..13.00}
• Predefined actions
• now: current time
• Can be assigned to an attribute and then used in a time constraint
• Duration: calculation of the duration of a message transmission

64 2IX20 UML Sequence diagrams: construction and validation


State Invariant

• Asserts that a certain condition must be fulfilled at a certain time


• Always assigned to a specific lifeline
• Evaluation before the subsequent event occurs
• If the state invariant is not true, either the model or the implementation
is incorrect
• Three alternative notations:

65 2IX20 UML Sequence diagrams: construction and validation


Validation

Consisency of sequence diagrams with


• Class diagrams
• Use case diagrams

66 2IX20 Interaction diagrams


Validation: Example

• Rule: Objects in [sd] should be instances of classes in [cd]


• Rule: Name of the message [sd] should match an operation in the
receiver’s class [cd]

67 2IX20 UML Sequence diagrams: construction and validation


Validation

Some more rules:


• Rule: If a message is sent from A to B [sd] then there should be an
association from the class of A to the class of B [cd]
• Rule: If use-case A generalizes use-case B [ucd] then the sequence
diagram of A should be a subgraph of the sequence diagram of B [sd].

Torre et al. describe 119 consistency rules for UML


https://doi.org/10.1016/j.jss.2018.06.029

68 2IX20 UML Sequence diagrams: construction and validation


Summary

Sequence diagrams Read


• Describe interactions between • Chapter 7 reader/Chapter 6
objects UML@Classroom
• Often: concrete scenario linked Do
to use case • Exercises 7.1-7.6
• Consistent with class diagram • Assignment 1: State machine
diagrams, Sequence diagrams

Look around for software bugs and


send them to me

69 2IX20 Interaction diagrams


Join the Round Table Discussion of Q3!

General info Courses


• Please help us improve your • 2IX20 – Software specification
courses! • 2IOI0 – DBL Process mining
And enjoy free lunch in the process • 2IS70 – DBL App development
• All feedback is useful, including
positive feedback!
• When?
Thursday 29 February 12:40-13:20, so
only your lunch break!
• How to join
Through the Canvas information page
(2IC02)
Or scan the QR code
Contact - Jort van Driel - Educational Officer of GEWIS - [email protected]

You might also like