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

Chapt 8

Uploaded by

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

Chapt 8

Uploaded by

deepblue5991
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 76

Object Oriented

Behavioral Modeling
(Dynamic UML
Design)

Chapter 8
Interaction Diagrams

• UML Specifies a number of interaction diagrams to model dynamic aspects


of the system
• Dynamic aspects of the system
– Messages moving among objects/
classes
– Flow of control among objects
– Sequences of events

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

• Activity & Swimlane Diagrams


– Emphasize and show flow of control among objects
Sequence Diagram

06/02/2024 5
Sequence Diagrams
• Describe the flow of messages,
events, actions between objects

• Show concurrent processes and


activations

• Show time sequences that are not


easily depicted in other diagrams

• Typically used during analysis and design to document and understand the logical flow of your system

Emphasis on time ordering!

06/02/2024 6
Sequence Diagram

06/02/2024 7
Sequence Diagram
Time Increasing -->

All lines should be horizontal to indicate instantaneous


actions. Additionally if ActivityA happens before
ActivityB, ActivityA must be above ActivityB
Lower = Later!
06/02/2024 8
Sequence Diagram Components
Objects: aStudent is a specific
instance of the Student class

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()

• A synchronous message requires a create()


response before the interaction can destroy()
continue. Synchronous message
• Asynchronous messages don't need a
Asynchronous message
reply for interaction to continue.
06/02/2024 12
Return message
Components: alt/else

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

collaborating to perform a particular task

• They provide a good view – although static - view of interaction between

objects which may be difficult to see at the class level

06/02/2024 20
Collaboration Diagram

• Represents a Collaboration and Interaction


• Collaboration­ set of objects and their interactions in a specific
context
• Interaction­ set of messages exchanged in a collaboration to
produce a desired result

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

• Objects­rectangles containing the object signature­:

– object name : object Class

– object name (optional) - starts with lowercase letter

– class name (mandatory) - starts with uppercase letter

• Objects connected by lines­actor can appear


06/02/2024 25
Objects

• Objects participating in a collaboration come in two flavors:

supplier and client


• Supplier objects are the objects that supply the method that is being called,
and therefore receive the message
• Client objects call methods on supplier objects, and therefore send messages.

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

• The connecting lines drawn between objects are links


• They enable you to see the relationships between objects
• This symbolizes the ability of objects to send messages to each other
• A single link can support one or more messages sent between objects

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

• Message icons have one or more messages associated with them

• Messages are composed of message text prefixed by a sequence number

• Time is not represented explicitly in a collaboration diagram, and as a

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

• Collaboration diagrams use syntax similar to sequence diagrams to indicate that


either a message iterates (is run multiple times) or is run conditionally
– An asterisk (*) indicates that a message runs more than once
– Or the number of times a message is repeated can be shown by numbers (for
example, 1..5)

06/02/2024 34
Conditional Messages

• To indicate that a message is run conditionally, prefix the message sequence

number with a conditional [guard] clause in brackets [ x = true ]:

[IsMediaOverdue ]

• This indicates that the message is sent only if the condition is met

06/02/2024 35
Collaboration vs Sequence Diagram

• In reality, sequence diagrams and collaboration diagrams show the

same information, but just present it differently.

• Not used as often as sequence diagrams but are closely related

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

1. Determine the scope of the diagram- the use case it relates to


2. Place the objects that participate in the collaboration on the diagram
– Remember to place the most important objects towards the center of the diagram.

3. If a particular object has a property or maintains a state that is important


to the collaboration, set the initial value of the property or state

06/02/2024 40
Steps to Creating a Collaboration Diagram

4. Create links between the objects

5. Create messages associated with each link

6. Add sequence numbers to each message corresponding to the

time-ordering of messages in the collaboration

06/02/2024 41
Creation and Deletion

• Unlike sequence diagrams, you don't show an object's lifeline in a


collaboration diagram
• If you want to indicate the lifespan of an object in a collaboration
diagram, you can use create and destroy messages to show when an
object is instantiated and destroyed

06/02/2024 42
Objects Changing State

• State of on object can be indicated

• Initial state is indicated with <<create>>

• 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?

• State machine diagrams are used to capture the behavior of a


software system.
• UML State machine diagrams can be used to model the behavior of
a class, a subsystem, a package, or even an entire system.
• It is also called a State chart or State Transition 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.

• States refer to the different combinations of information that an


object can hold, not how the object behaves.

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:

• The state machine diagram where the class it is attached:

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.

• Final State or End Point


• An arrow pointing to a filled circle nested inside another circle represents the
final action state.

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

You might also like