Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 15 UML Interaction Diagrams 1CS6359 Fall 2012 John Cole.

Similar presentations


Presentation on theme: "Chapter 15 UML Interaction Diagrams 1CS6359 Fall 2012 John Cole."— Presentation transcript:

1 Chapter 15 UML Interaction Diagrams 1CS6359 Fall 2012 John Cole

2 What are Interaction Diagrams? Illustrate how objects interact through messages Two types: Sequence Diagrams and Communication Diagrams 2CS6359 Fall 2012 John Cole

3 Example Code Public class A { Private BB myB = new BB(); Public void doOne() { myB.doTwo(); myB.doThree(); } 3CS6359 Fall 2012 John Cole

4 Sequence Diagram A B 4CS6359 Fall 2012 John Cole

5 Sequence Diagram 5CS6359 Fall 2012 John Cole

6 Guideline Spend time doing dynamic modeling with interaction diagrams, not just static object modeling with class diagrams This makes you think about how things happen, not just the objects you need 6CS6359 Fall 2012 John Cole

7 Sequence vs. Communication UML tools usually emphasize sequence Easier to see call flow sequence—read from top to bottom Communication diagrams are more space- efficient Communication Diagrams expand top to bottom; Sequence Diagrams expand left to right 7CS6359 Fall 2012 John Cole

8 Common Notation CS6359 Fall 2012 John Cole8

9 Singleton Objects Only one instance of the class instantiated at any time. CS6359 Fall 2012 John Cole9

10 Lifeline Boxes Lifeline is a dashed (or solid, in UML 2) line below the object. 10CS6359 Fall 2012 John Cole

11 Messages CS6359 Fall 2012 John Cole11

12 Focus of Control The bar on the left is an Execution Specification bar. Indicates focus of control CS6359 Fall 2012 John Cole12

13 Reply or Returns Use the message syntax returnVar=Message(parameter) Using a reply or return message at the end of an activation bar CS6359 Fall 2012 John Cole13

14 Messages to Self Message sent to itself with a nested activation bar CS6359 Fall 2012 John Cole14

15 Creation of Instances Dashed line with filled arrow for synchronous message, open if async. Name “create” is not required; it’s a UML idiom CS6359 Fall 2012 John Cole15

16 Lifelines and Object Destruction Show explicit destruction of an object, such a when a database connection is closed CS6359 Fall 2012 John Cole16

17 Diagram Frames These support conditionals and looping CS6359 Fall 2012 John Cole17

18 Frame Operators Frame Operator Meaning 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. Can be enhanced to define for loop OptOptional fragment that executes if guard is true ParParallel fragments that execute in parallel RegionCritical region within which only one thread can run A “guard” is a Boolean test in brackets over the line to which it belongs CS6359 Fall 2012 John Cole18

19 Conditional Messages CS6359 Fall 2012 John Cole19

20 UML 1.x Conditionals CS6359 Fall 2012 John Cole20

21 Conditional If…Else CS6359 Fall 2012 John Cole21

22 Code to Iterate Over Collection 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; } //.. } CS6359 Fall 2012 John Cole22

23 Implicit Iteration CS6359 Fall 2012 John Cole23

24 Nesting Frames CS6359 Fall 2012 John Cole24

25 Relating Interaction Diagrams Interaction Occurrence (or Use) is a reference to an interaction within another interaction. CS6359 Fall 2012 John Cole25

26 Invoking Static Methods Metaclasses or static classes are instances of themselves. Calling a static method uses the name of the class, not the name of the instance. CS6359 Fall 2012 John Cole26

27 Polymorphic Messages Multiple sequence diagrams: One to the superclass, one to each case, each starting with a found polymorphic message (next slide) CS6359 Fall 2012 John Cole27

28 Polymorphic Messages CS6359 Fall 2012 John Cole28

29 Async and Sync Calls Async (non-blocking) calls are a stick (unfilled) arrow, sync are a filled arrow This can be used for multi-threading Public class ClockStarter { Public void startClock { Thread t = new Thread(new Clock)); t.start(); System.runFinalization(); // } CS6359 Fall 2012 John Cole29

30 Async Calls CS6359 Fall 2012 John Cole30

31 Links Connection path between objects. Navigation and visibility. Instance of an association. Multiple messages and messages both ways CS6359 Fall 2012 John Cole31

32 Creation of Instances Message named Create. If some other name is used, use the UML stereotype > to indicate. Message can include parameters. UML tagged value [new] to indicate creation CS6359 Fall 2012 John Cole32

33 Message Number Sequencing If ordering is important, indicate this with sequence numbers. The first message is not numbered Order and nesting of subsequent numbers is shown with levels (next slide) CS6359 Fall 2012 John Cole33

34 Sequencing CS6359 Fall 2012 John Cole34

35 Conditional Messages Show this with the condition in brackets CS6359 Fall 2012 John Cole35

36 Mutually Exclusive Conditionals Equivalent of If…else. Modify the sequence expression with a letter: CS6359 Fall 2012 John Cole36

37 Iteration CS6359 Fall 2012 John Cole37

38 Iteration Over a Collection CS6359 Fall 2012 John Cole38


Download ppt "Chapter 15 UML Interaction Diagrams 1CS6359 Fall 2012 John Cole."

Similar presentations


Ads by Google