Title: UML Interaction Diagrams
1UML Interaction Diagrams
2Quick!
- What is the purpose of interaction diagrams?
3Session Goals
- Understand
- The difference between a class and an object
- Sequence diagrams
- Collaboration diagrams
4Classes vs Objects
- Classes represent abstractions
- Define structure and behavior
- We cannot interact with an abstraction
- An object is an instance of an class
- Run-time entity
- Occupies space in memory
- Can participate in an interaction
5Classes vs. Objects
Java
public class Engine int
numberOfCylindars boolean fuelInjected
public Engine(int cylindarCount,
boolean fuelInjected) public int
getNumberOfCylindars() public boolean
isFuelInjected()
public class Car Engine engine public
Car (int cylindarCount,
boolean fuelInjected) engine new
Engine(cylindarCount,
fuelInjected)
6Classes vs. Objects
Java
createsobject
class
reference
public class Engine int
numberOfCylindars boolean fuelInjected
public Engine(int cylindarCount,
boolean fuelInjected) public int
getNumberOfCylindars() public boolean
isFuelInjected()
public class Car Engine engine public
Car (int cylindarCount,
boolean fuelInjected) engine new
Engine(cylindarCount,
fuelInjected)
7Classes vs. Objects
C
class BilliardBall protected int color
int number Position location public
void setPosition (Position p) void hitBy
(BilliardBall b) void draw()
class Position protected double x
double y double z public void moveTo
(double x, double y,
double z) void transform (Matrix by)
8Classes vs. Objects
C
object
class
class BilliardBall protected int color
int number Position location public
void setPosition (Position p) void hitBy
(BilliardBall b) void draw()
class Position protected double x
double y double z public void moveTo
(double x, double y,
double z) void transform (Matrix by)
9Objects in UML
- Objects
- Have their own notation in UML
- Represented by rectangles (like classes) but
their label is underlined - There are multiple ways to denote an object
Class
Object
objectNameClassName
ClassName
ClassName
objectName
10Objects in UML
objectNameClassName
The object is of type Classname and has the name
objectName
objectName
The object has the name objectName but no known
associated type
ClassName
The object is of type Classname but has no known
associated name
11Objects in UML
eightBallBilliardBall
An object called eightball which is an instance
of BillardBall
textWindow
The object has the name textWindow but we do not
know of exactly what type the object is
DiskDrive
The object is of type DiskDrive but we do not
know the name of the object
12Interaction Diagrams
- Class Diagrams
- Show static relationships between classes
- Interaction Diagrams
- Show dynamic interactions between objects
- Basically, what services are used by what classes
and when
13How do the classes work together?
14Order
Quote
generateQuote() calculateBasePrice()
void calculateDiscounts() void sendQuote()
void
setQuote(quoteInfo String) void
Customer
-modeMgr
getDiscount() double getEmail () String
OrderLine
getDiscount() double getEmail () String
15TimeManager
SixtySecondTimer
TimeManager() setDisplay(newDisplay
Display) void setModeManager(newModeMgr
ModeManager) void setAlarm(newAlarm Alarm)
void
SixtySecondTimer() setTimeManager (newTimeMgr
TimeManager void start() void
-timer
-timeMgr
Clock
ModeManager
-modeMgr
Display
Clock() start() void
ModeManager()
Display()
-buttonMgr
ButtonManager
Alarm
-alarm
ButtonManager() setModeManager(newModeMgr
ModeManager) void setTimeManager(newTimeMgr
TimeManager) void
Alarm()
16Interaction Diagrams
- Since Interaction Diagrams represent run-time
interactions, they use objects rather than
classes - There are two common Interaction Diagrams
- Sequence Diagrams
- Collaboration Diagrams
17Sequence Diagrams vs Collaboration Diagrams
- Both diagrams convey the same information the
order in which objects call each other under a
particular set of circumstances - Sequence Diagrams
- Tend to be more readable with respect to the time
ordering of events - Collaboration Diagrams
- Provide a better spatial representation of more
complicated interactions
18Sequence Diagrams
- Sequence Diagrams are constructed by placing
objects horizontally across the top of a diagram - Lifelines extend down from each object
- Various arrow types extend between lifeline to
indicate messages (i.e., method calls) occurring
between classes - The arrow types have different meanings
19Class Diagram - Example
20Sequence Diagrams Example
21Sequence Diagrams Example
objects
lifeline
activation box
messages
22Sequence Diagrams Variation
23Sequence Diagrams Variation
return, denotes return of control
24Class Diagram - Example
25Sequence Diagrams Example
Adapted from Fowler, UML Distilled, p 68
26Sequence Diagrams Example
Adapted from Fowler, UML Distilled, p 68
iterator
27Class Diagram - Example
28Sequence Diagrams Example
29Sequence Diagrams Example
return, denotes return of control
Notice that control is always returned to the
caller!
30Collaboration Diagrams
- Collaboration Diagrams look similar to Class
Diagrams - Collaboration Diagrams consist of objects and
associations between theses objects - The associations are labeled with a message and a
direction, indicating one object is calling
another - The messages are numbered to show the order in
which they occur
31Collaboration Diagram Example
32Notes on Interaction Diagrams
- Sequence and Collaboration Diagrams are good
tools for showing a specific sequence - They do not lend themselves well to showing
alternative flows - It is possible to show alternative flows in
sequence diagrams but the diagrams can get
cluttered quickly
33Alternative Flow Example
Branch point with guard conditions
34Asynchronous Messages
- So far we have illustrated synchronous messages
- Synchronous messages prevent the caller from
continuing until the message is processed by the
receiver - This is the usual way in which objects interact
- Asynchronous communication can also be modeled
- Asynchronous messages enable the caller to do
something else - Asynchronous messages sometimes requires an
acknowledgement or answer message
35Asynchronous Messages Class Diagram
36Asynchronous Messages Sequence Diagram
37Asynchronous Messages Example
Asynchronous Messages
38Scenarios and Sequence Diagrams
- Scenarios are often give rise to sequence
diagrams - Once system roles are identified, scenarios are
translated to sequence diagrams that involve
different system roles - This provides a visual representation of expected
system behavior - The system can be executed, the resulting
interaction also captured in a sequence diagram
and the two diagrams compared - There exist case tools which can help automate
this process
39Scenarios and Sequence Diagrams - Example
- The following use case is represented by the
previous sequence diagram