Download presentation
Presentation is loading. Please wait.
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 Same interaction in a “network” diagram description Communication Diagram sequence numbers
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 NOTE: If you need to extend you’ve run out of space lifeline
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 asynchronous with dashed lines also activation bar
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 this.clear() representing a message sent to the same object; not just to an object of the same class
17
Fig. 15.10 New Object Creation dashed line because UML says so
18
Fig. 15.11 I’m not sure where this fits in the Java paradigm?
19
Fig. 15.12 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. [more items] 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: AltAlternative fragment for mutual exclusion conditional logic expressed in the guards. LoopLoop 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) OptOptional fragment that executes if guard is true. ParParallel fragments that execute in parallel. RegionCritical region within which only one thread can run. Frame Operator Meaning
22
Fig. 15.14 I like this better
23
Fig. 15.15
24
Fig. 15.16
25
Sample Code: public class Sale { private List lineItems = new ArrayList (); 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 simplifies the first diagram sd == sequence 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
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.