Download presentation
Presentation is loading. Please wait.
Published byRodger Cain Modified over 9 years ago
1
Chapter 4: UML Interaction Diagrams
2
Objective Provide a reference for frequently used UML interaction diagram notation- sequence and communication diagrams.
3
4.1. Sequence and Communication Diagrams Interaction diagram includes –sequence diagrams –communication diagrams Sequence diagrams –illustrate interactions in a kind of fence format each new object is added to the right Communication diagrams –illustrate object interactions in a graph or network format, objects can be placed anywhere on the diagram
4
4.1. Sequence and Communication Diagrams public class A { private B myB = new B(); public void doOne() { myB.doTwo();myB.doThree();} // … }
5
4.1. Sequence and Communication Diagrams
6
Sequence vs. Communication Diagrams? TypeStrengthsWeaknesses sequence clearly shows sequence or time ordering of messages large set of detailed notation options forced to extend to the right when adding new objects; consumes communication space economical flexibility to add new objects in two dimensions more difficult to see sequence of messages fewer notation options
7
4.1. Sequence and Communication Diagrams Example Sequence Diagram: makePayment public class Sale { private Payment payment; public void makePayment( Money cashTendered ) { payment = new Payment( cashTendered ); //… } // … }
8
4.1. Sequence and Communication Diagrams Example Communication Diagram: makePayment
9
4.2. Novice UML Modelers Don't Pay Enough Attention to Interaction Diagrams! Spend time doing dynamic object modeling, not just static object modeling. –think through the concrete details of what messages to send, and to whom, and in what order, –that the "rubber hits the road" in terms of thinking through the true OO design details.
10
4.3. Common UML Interaction Diagram Notation Illustrating Participants with Lifeline Boxes
11
4.3. Common UML Interaction Diagram Notation Basic Message Expression Syntax return = message(parameter : parameterType) : returnType –Examples initialize(code)initialize d = getProductDescription(id) d = getProductDescription(id:ItemID) d = getProductDescription(id:ItemID) : ProductDescription d = getProductDescription(id:ItemID) : ProductDescription
12
4.3. Common UML Interaction Diagram Notation Singleton Objects –only one instance of a class instantiated
13
4.4. Basic Sequence Diagram Notation Lifeline Boxes and Lifelines
14
4.4. Basic Sequence Diagram Notation Illustrating Reply or Returns
15
4.4. Basic Sequence Diagram Notation Messages to "self" or "this"
16
4.4. Basic Sequence Diagram Notation Creation of Instances
17
4.4. Basic Sequence Diagram Notation Object Lifelines and Object Destruction
18
4.4. Basic Sequence Diagram Notation Diagram Frames in UML Sequence Diagrams –Looping
19
4.4. Basic Sequence Diagram Notation 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. region Critical region within which only one thread can run. par Parallel fragments that execute in parallel.
20
4.4. Basic Sequence Diagram Notation –Conditional Messages
21
4.4. Basic Sequence Diagram Notation –Mutually Exclusive Conditional Messages
22
4.4. Basic Sequence Diagram Notation –Iteration Over a Collection
23
4.4. Basic Sequence Diagram Notation
24
public class Sale { private List lineItems = new ArrayList (); new ArrayList (); public Money getTotal() { Money total = new Money(); Money subtotal = null; for ( SalesLineItem lineItem : lineItems ){ subtotal = lineItem.getSubtotal(); total.add( subtotal ); total.add( subtotal ); } return total; return total; } // … }
25
4.4. Basic Sequence Diagram Notation –Nesting of Frames
26
4.4. Basic Sequence Diagram Notation How to Relate Interaction Diagrams?
27
4.4. Basic Sequence Diagram Notation Messages to Classes to Invoke Static Methods public class Foo { public void doX() { // static method call on class Calendar Locale[] locales = Calendar.getAvailableLocales(); // … } // … }
28
4.4. Basic Sequence Diagram Notation Polymorphic Messages and Cases
29
4.4. Basic Sequence Diagram Notation Asynchronous and Synchronous Calls
30
4.4. Basic Sequence Diagram Notation public class ClockStarter { public void startClock() { Thread t = new Thread( new Clock() ); // asynchronous call to the 'run' method on the Clock // asynchronous call to the 'run' method on the Clock t.start(); t.start(); // example follow-on message // example follow-on messageSystem.runFinalization(); } // … } // 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 // … }} // … // …}
31
4.5. Basic Communication Diagram Notation Links All messages flow on the same line
32
4.5. Basic Communication Diagram Notation Messages Don't number the starting message.
33
4.5. Basic Communication Diagram Notation Messages to "self" or "this"
34
4.5. Basic Communication Diagram Notation Creation of Instances
35
4.5. Basic Communication Diagram Notation Message Number Sequencing –The first message is not numbered. –The order and nesting of subsequent messages is shown with a legal numbering scheme in which nested messages have a number appended to them.
36
4.5. Basic Communication Diagram Notation
38
Conditional Messages
39
4.5. Basic Communication Diagram Notation Mutually Exclusive Conditional Paths
40
4.5. Basic Communication Diagram Notation Iteration or Looping
41
4.5. Basic Communication Diagram Notation Iteration Over a Collection
42
4.5. Basic Communication Diagram Notation Messages to a Classes to Invoke Static Methods
43
4.5. Basic Communication Diagram Notation Polymorphic Messages and Cases
44
4.5. Basic Communication Diagram Notation Asynchronous and Synchronous Calls
45
Questions & Answers
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.