UML Interaction Diagrams - PowerPoint PPT Presentation

1 / 36
About This Presentation
Title:

UML Interaction Diagrams

Description:

public Car (int cylindarCount, boolean fuelInjected) { engine = new Engine(cylindarCount, ... Quote getDiscount() : double getEmail () : String. OrderLine ... – PowerPoint PPT presentation

Number of Views:69
Avg rating:3.0/5.0
Slides: 37
Provided by: harold98
Category:

less

Transcript and Presenter's Notes

Title: UML Interaction Diagrams


1
UML Interaction Diagrams
  • April 16 2008

2
Quick!
  • What is the purpose of interaction diagrams?

3
Session Goals
  • Understand
  • The difference between a class and an object
  • Sequence diagrams
  • Collaboration diagrams

4
Classes 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

5
Classes 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)
6
Classes 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)
7
Classes 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)
8
Classes 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)
9
Objects 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
10
Objects 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
11
Objects 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
12
Interaction 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

13
How do the classes work together?
14
Order
Quote
generateQuote() calculateBasePrice()
void calculateDiscounts() void sendQuote()
void
setQuote(quoteInfo String) void
Customer
-modeMgr
getDiscount() double getEmail () String
OrderLine
getDiscount() double getEmail () String
15
TimeManager
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()
16
Interaction Diagrams
  • Since Interaction Diagrams represent run-time
    interactions, they use objects rather than
    classes
  • There are two common Interaction Diagrams
  • Sequence Diagrams
  • Collaboration Diagrams

17
Sequence 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

18
Sequence 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

19
Class Diagram - Example
20
Sequence Diagrams Example
21
Sequence Diagrams Example
objects
lifeline
activation box
messages
22
Sequence Diagrams Variation
23
Sequence Diagrams Variation
return, denotes return of control
24
Class Diagram - Example
25
Sequence Diagrams Example
Adapted from Fowler, UML Distilled, p 68
26
Sequence Diagrams Example
Adapted from Fowler, UML Distilled, p 68
iterator
27
Class Diagram - Example
28
Sequence Diagrams Example
29
Sequence Diagrams Example
return, denotes return of control
Notice that control is always returned to the
caller!
30
Collaboration 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

31
Collaboration Diagram Example
32
Notes 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

33
Alternative Flow Example
Branch point with guard conditions
34
Asynchronous 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

35
Asynchronous Messages Class Diagram
36
Asynchronous Messages Sequence Diagram
37
Asynchronous Messages Example
Asynchronous Messages
38
Scenarios 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

39
Scenarios and Sequence Diagrams - Example
  • The following use case is represented by the
    previous sequence diagram
Write a Comment
User Comments (0)
About PowerShow.com