Chapt 8
Chapt 8
Behavioral Modeling
(Dynamic UML
Design)
Chapter 8
Interaction Diagrams
06/02/2024 2
Dynamic Diagram Types
• Interaction Diagrams - Set of objects or roles and the messages that can be passed among them.
The sub types are
Sequence Diagrams - emphasize time ordering
Communication Diagrams or Collaboration diagram - emphasize structural ordering
• Sequence and communication diagrams are semantically similar, they represent the same
information
• We can turn communication diagram into sequence diagrams and vice versa
• Communication diagram are very useful for visualizing relationship between objects that
collaborate with each other to perform a specific task. (Which is difficult to determine from
sequence diagram )
3
06/02/2024
Dynamic Diagram Types
• State Diagrams
– State machine consisting of states, transitions, events and
activities of an object
06/02/2024 5
Sequence Diagrams
• Describe the flow of messages,
events, actions between objects
• Typically used during analysis and design to document and understand the logical flow of your system
06/02/2024 6
Sequence Diagram
06/02/2024 7
Sequence Diagram
Time Increasing -->
Generic (unnamed)
Specific Generic
objects (unnamed)
Instance of an objects of class type Seminar
Object and Course
06/02/2024 9
Sequence Diagram Components
execution
lifeline
06/02/2024 10
Sequence Diagram Components
Method call
Return value
06/02/2024 11
Sequence Diagram Components
c : Client o : ODBCProxy
create() : Transaction
setActions(a, b, c)
setValues(a, 3, 4)
setValues(b, c, 7)
(committed)
destroy()
06/02/2024 13
Components: option
06/02/2024 14
Components: loop
06/02/2024 15
Rules of thumb
• Rarely use options, loops, alt/else
– These constructs complicate a diagram and make them hard to read/interpret
– Frequently it is better to create multiple simple diagrams
• Create sequence diagrams for use cases when it helps clarify and
visualize a complex flow
• Remember: The goal of UML is communication and understanding
06/02/2024 16
Example of Sequence Diagram for ATM
06/02/2024 17
Collaboration or Communication
Diagrams
06/02/2024 18
What is a Collaboration Diagram
• Collaboration diagrams are extensions of object diagram which illustrate interactions
between objects
• The collaboration diagram illustrates messages being sent between classes and objects
(instances).
• Collaboration diagrams express both the context of a group of objects (through objects and
links) and the interaction between these objects (by representing message broadcasts)
• They provide an alternate view of the same information as sequence diagrams.
• In sequence diagrams, the focus is the ordering of the messages over time; in
communication diagrams the focus is the structure of the messages that pass between the
objects in the interaction.
• These diagrams illustrate the flow of messages between objects and the implied
relationships between classes.
06/02/2024 19
Purpose of the Collaboration Diagram
• They are very useful for visualizing the relationship between objects
06/02/2024 20
Collaboration Diagram
06/02/2024 21
Ex. Collaboration Diagram
06/02/2024 22
Collaboration Diagram Elements
• There are three primary elements of a collaboration
diagram:
– Objects
– Links
– Messages
06/02/2024 23
Collaboration Diagram Syntax
AN ACTOR
AN OBJECT anObject:aClass
AN ASSOCIATION
A MESSAGE aMessage()
06/02/2024 24
Objects
06/02/2024 26
transaction object acts as a supplier to the UI (user interface) client object.
in turn, the fine object is a supplier to the transaction client object.
06/02/2024 27
Links
06/02/2024 28
• The visual representation of a link is a straight line between two objects.
• If an object sends messages to itself, the link carrying these messages is represented as a loop icon.
• This loop can be seen on both the UI object and the Transaction object.
06/02/2024 29
Messages
• An interaction is implemented by a group of objects that collaborate by
exchanging messages
• Messages in collaboration diagrams are shown as arrows pointing from
the Client object to the Supplier object.
• Typically, messages represent a client invoking an operation on a
supplier object
06/02/2024 30
Messages
result the various messages are numbered to indicate the sending order
06/02/2024 31
Flow by Numbers
1. Enter Borrower ID
1.1 CalcAmtCanBorrow
1.1.1 <<create>>
1.1.2 CalcBorrowerFines
1.1.3 GetBorrowersCheckedOutMedia
1.1.4 IsMediaOverdue
1.1.5 Amt Can Borrow
1.2 Display Invalid User Msg
06/02/2024 32
Message Flow Notation
Synchronous
Flow of control
Asynchronous
Return
06/02/2024 33
Iterating Messages
06/02/2024 34
Conditional Messages
[IsMediaOverdue ]
• This indicates that the message is sent only if the condition is met
06/02/2024 35
Collaboration vs Sequence Diagram
06/02/2024 36
Sequence diagram is better at ‘time ordering’
06/02/2024 37
Collaboration diagram is better at showing the relationship between objects
06/02/2024 38
Number of Messages
• In sequence diagrams, each message icon represents a single message.
• In collaboration diagrams, a message icon can represent one or more
messages.
• Notice between the Transaction and Fine objects - there is a single
message icon, but there are two messages (1.1.1 and 1.1.2) associated
with the icon.
06/02/2024 39
Steps to Creating a Collaboration Diagram
06/02/2024 40
Steps to Creating a Collaboration Diagram
06/02/2024 41
Creation and Deletion
06/02/2024 42
Objects Changing State
• If an object changes significantly during an interaction, you can add a new instance
of the object to the diagram, draw a link between them and add a message with the
stereotype <<become>>
06/02/2024 43
06/02/2024 44
Change State of an Object
06/02/2024 45
Example Collaboration Diagram
Example Collaboration Diagram
06/02/2024 47
State Machine Diagram
06/02/2024 48
What is a State Machine Diagram?
06/02/2024 49
What is a State Machine Diagram?
• A state machine is any device that stores the status of an object
at a given time and can change status or cause other actions
based on the input it receives.
06/02/2024 50
State diagram symbols and components
• This list summarizes the most common shapes you may encounter.
• Composite state
– Generally, composite state is defined as state that has substates
(nested states). Substates could be sequential (disjoint) or concurrent
(orthogonal).
06/02/2024 51
State diagram symbols and components…
• Initial state
– The initial state symbol is used to indicate the beginning of a state
machine diagram.
• Final state
– This symbol is used to indicate the end of a state machine diagram.
06/02/2024 52
State diagram symbols and components…
• Choice pseudo state
– A diamond symbol that indicates a dynamic condition with branched
potential results.
06/02/2024 53
State diagram symbols and components…
• State
– A rectangle with rounded corners that indicates the current nature of
an object.
• Transition
– An arrow running from one state to another that indicates a changing
state.
06/02/2024 54
State diagram symbols and components…
• Trigger
• A type of message that actively moves an object from state to state, written above the
transition arrow.
• Event
• Guard
– A Boolean condition that allows or stops a transition, written above the transition
arrow.
06/02/2024 55
State diagram symbols and components…
• State Actions
• Self-Transitions
– A state can have a transition that returns to itself, as in the following
diagram. This is most useful when an effect is associated with the
transition.
06/02/2024 56
Example
• The Digital Clock State Machine diagram example below
shows the interface of a simple digital clock:
06/02/2024 57
The state Diagram for modeling the behavior of the Digital Clock.
06/02/2024 58
How to draw a State chart diagram?
• To draw a state diagram, one must identify all the possible states of any particular entity.
1. Identify entities that have complex behavior or identify a class participating in behavior whose
lifecycle is to be specified
2. Model states – Determine the initial and final states of the entity
3. Model transitions
4. Model events – Identify the events that affect the entity
5. Working from the initial state, trace the impact of events and identify intermediate states
6. Identify any entry and exit actions on the states
7. Expand states using substates where necessary
8. If the entity is a class, check that the action in the state are supported by the operations and
relationships of the class, and if not extend the class
9. Refine and elaborate as required
06/02/2024 59
Rules
• Following rules must be considered while drawing a state chart diagram:
1. The name of a state transaction must be unique.
2. The name of a state must be easily understandable and describe the
behavior of a state.
3. If there are multiple objects, then only essential objects should be
implemented.
4. Proper names for each transition and an event must be given.
06/02/2024 60
Activity Diagram
06/02/2024 61
What is an Activity Diagram?
• An activity diagram visually presents a series of actions or flow of
control in a system similar to a flowchart or a data flow diagram.
• Activity diagrams are often used in business process modeling.
• They can also describe the steps in a use case diagram.
• Activities modeled can be sequential and concurrent.
• In both cases an activity diagram will have a beginning (an initial state)
and an end (a final state).
06/02/2024 62
Basic Activity Diagram Notations and Symbols
• Initial State or Start Point
– A small filled circle followed by an arrow represents the initial action state or the start point for
any activity diagram. For activity diagram using swimlanes, make sure the start point is placed in
the top left corner of the first column.
06/02/2024 63
Basic Activity Diagram Notations and Symbols…
• Activity or Action State
– An action state represents the non-interruptible action of objects.
• Action Flow
– Action flows, also called edges and paths, illustrate the transitions
from one action state to another. They are usually drawn with an
arrowed line.
06/02/2024 64
Basic Activity Diagram Notations and Symbols…
• Object Flow
– Object flow refers to the creation and modification of objects by
activities.
– An object flow arrow from an action to an object means that the
action creates or influences the object.
– An object flow arrow from an object to an action indicates that the
action state uses the object.
06/02/2024 65
Basic Activity Diagram Notations and Symbols…
• Decisions and Branching
– A diamond represents a decision with alternate paths.
– When an activity requires a decision prior to moving on to the next
activity, add a diamond between the two activities.
– The outgoing alternates should be labeled with a condition or guard
expression.
– You can also label one of the paths "else."
06/02/2024 66
Basic Activity Diagram Notations and Symbols…
• Guards
– In UML, guards are a statement written next to a decision diamond
that must be true before moving next to the next activity.
– These are not essential, but are useful when a specific answer, such as
"Yes, three labels are printed," is needed before moving forward.
06/02/2024 67
Basic Activity Diagram Notations and Symbols…
• Synchronization
– A fork node: is used to split a single incoming flow into multiple concurrent flows.
– It is represented as a straight, slightly thicker line in an activity diagram.
– A join node: joins multiple concurrent flows back into a single outgoing flow.
– A fork and join node used together are often referred to as synchronization.
06/02/2024 68
Basic Activity Diagram Notations and Symbols…
• Merge Event
– A merge event brings together multiple flows that are not concurrent.
• Swim lanes
– A swim lane is a way to group activities performed by the same actor
on an activity diagram or activity diagram or to group activities in a
single thread.
06/02/2024 69
Steps to model Activity Diagram
1. Identify candidate use cases, through the examination of
business workflows
2. Identify pre- and post-conditions (the context) for use cases
3. Model workflows between/within use cases
4. Model complex workflows in operations on objects
5. Model in detail complex activities in a high level activity
Diagram
06/02/2024 70
ATM Machine Activity diagram
06/02/2024 71
Another Example
06/02/2024 72
06/02/2024 73
Exercise
Activity Diagram - Modeling a Word Processor
The activity diagram example below describes the workflow for a word process to create a document through
the following steps:
1. Open the word processing package.
2. Create a file.
3. Save the file under a unique name within its directory.
4. Type the document.
5. If graphics are necessary, open the graphics package, create the graphics, and paste the graphics into the
document.
6. If a spreadsheet is necessary, open the spreadsheet package, create the spreadsheet, and paste the
spreadsheet into the document.
7. Save the file.
8. Print a hard copy of the document.
9. Exit the word processing package.
06/02/2024 74
Possible answer for the
previous exercise:
06/02/2024 75
END of the Course