Interaction Diagrams - PowerPoint PPT Presentation

1 / 46
About This Presentation
Title:

Interaction Diagrams

Description:

Chapter 15 Interaction Diagrams – PowerPoint PPT presentation

Number of Views:249
Avg rating:3.0/5.0
Slides: 47
Provided by: Dmit59
Category:

less

Transcript and Presenter's Notes

Title: Interaction Diagrams


1
Chapter 15
  • Interaction Diagrams

2
Most Common
  • Sequence Diagram
  • Communication Diagram
  • Sequence Diagrams illustrate interactions between
    classes of a program using class methods as
    message names,

3
Sample Code
public class A private B myB null
public A () myB new B()
public void doOne() myB.doTwo()
myB.doThree()
4
Fig. 15.1
duration of doOne() activity
5
Fig. 15.2
Communication Diagram
sequence numbers
Same interaction in a network diagram
description
6
Strengths and Weaknesses
  • UML has put more thought into SDs
  • Better tool support for SDs
  • Better at showing sequence
  • CDs are more space efficient, boxes can go
    anywhere
  • Easier to modify a CD
  • CDs are vertical so fit on narrow pages of a
    book

7
Fig. 15.3
lifeline
NOTE If you need to extend youve run out of
space
8
Fig. 15.4
NOTE If you need to extend you can come back
to the left.
9
Static vs Dynamic View
  • The Class Diagram is a static view of the program
    while the Sequence Diagram is a dynamic view.
    Both are useful.

10
Fig. 15.5
Common Notation
11
Fig. 15.6
12
Singleton Pattern
  • http//en.wikipedia.org/wiki/Singleton_pattern

public class Singleton // Private
constructor suppresses // generation of a
(public) default constructor private
Singleton() private static class
SingletonHolder private static
Singleton instance new Singleton()
public static Singleton getInstance()
return SingletonHolder.instance

13
Fig. 15.7
Messages
also activation bar
asynchronous with dashed lines
14
Message Return Values
  • Two ways to show the return result
  • Using the message syntax
  • returnVar message(parameter).
  • Using a reply (or return) message line at the end
    of an activation bar

15
Fig. 15.8
16
Fig. 15.9
representing a message sent to the same object
not just to an object of the same class
this.clear()
17
Fig. 15.10
New Object Creation
dashed line because UML says so
18
Fig. 15.11
Im not sure where this fits in the Java paradigm?
19
Fig. 15.12
more items
I think this notation is starting to get out of
hand. I, because I am drawing on the whiteboard,
would draw and arrow like I have.
In general, these are called diagram frames
20
Fig. 15.13
I have no easy alternative to this except to not
bother trying to describe an entire algorithm.
21
Diagram Frames
Frame Operator
Meaning
Alt Alternative fragment for mutual exclusion conditional logic expressed in the guards.
Loop Loop fragment while guard is true. Can also write loop(n) to indicate looping n times. There is discussion that the specification will be enhanced to define a FOR loop, such as loop(i, 1, 10)
Opt Optional fragment that executes if guard is true.
Par Parallel fragments that execute in parallel.
Region Critical region within which only one thread can run.
22
Fig. 15.14
I like this better
23
Fig. 15.15
24
Fig. 15.16
25
Sample Code
public class Sale private
ListltSalesLineItemgt lineItems new
ArrayListltSalesLineItemgt() public Money
getTotal() Money total new Money()
Money subtotal null for (
SalesLineItem lineItem lineItems )
subtotal lineItem.getSubtotal()
total.add( subtotal ) return total
//
26
Fig. 15.17
An alternative for Figure 15.16 nothing is
official.
27
Fig. 15.18
nested loops
28
Fig. 15.19
sd sequence diagram
simplifies the first diagram
29
Fig. 15.20
30
Code Example
public class Foo public void doX()
// static method call on class Calendar
Locale locales Calendar.getAvailableLocales()
// //
31
Fig. 15.21
abstract method call
individual implementations
32
Fig. 15.22
asynchronous call
Guideline This arrow difference is subtle. And
when wall sketching UML, it is common to use a
stick arrow to mean a synchronous call because
it's easier to draw. Therefore, when reading a
UML interaction diagram don't assume the shape
of the arrow is correct!
33
Code Example
public class ClockStarter public void
startClock() Thread t new Thread( new
Clock() ) t.start() //
asynchronous call to the 'run' method on the
Clock System.runFinalization()
// example follow-on message //
// objects should implement the Runnable
interface // in Java to be used on new threads
public class Clock implements Runnable
public void run() while ( true ) //
loop forever on own thread
// //
34
Fig. 15.23
35
Fig. 15.24
36
Fig. 15.25
37
Fig. 15.26
38
Fig. 15.27
39
Fig. 15.28
40
Fig. 15.29
41
Fig. 15.30
42
Fig. 15.31
43
Fig. 15.32
44
Fig. 15.33
45
Fig. 15.34
46
Fig. 15.35
Write a Comment
User Comments (0)
About PowerShow.com