150 likes | 407 Views
15. UML Interaction Diagrams. CSE 5324 Quiz 12 due at 5 PM, Saturday, 20 September 2014. 15. UML Interaction Diagrams. Objective: How to use sequence and communication diagrams. Introduction: They are UML’s means for modeling dynamic objects.
E N D
15. UML Interaction Diagrams CSE 5324 Quiz 12 due at 5 PM, Saturday, 20 September 2014
15. UML Interaction Diagrams • Objective: How to use sequence and communication diagrams. • Introduction: • They are UML’s means for modeling dynamic objects. • Illustrative examples of both merely introduce the UML notation here. • Later these very important diagrams will illustrate the key principles in OO design.
15.1 Sequence and Comm Diagrams Figure 15.1 Sequence Diagram. Figure 15.2 Communication Diagram. • Figure 15.1 shows a sequence diagram that models class A’s doOne() method calling class B’s doTwo() and doThree() methods. • It looks like a fence with class-named posts and method-named wires. • Figure 15.2 shows the corresponding communication diagram. • Its class-named blocks can be drawn anywhere, which makes it easier to sketch but less powerful than the sequence diagram, which offers more notation, semantics, tool support. • And the sequence diagram’s top-to-bottom call-flow sequence is clearer than the communication diagram’s sequence numbers.
15.1-.2 Seq & CommDiag (continued) Figure 15.3 Sequence Diagram. Figure 15.4 Communication Diagram. • Figure 15.3’s sequence diagram models… • A customer sending a makePayment(cashTendered) message to an instance of Register, • Register passing it on to Sale, and • Sale using the cashTendered to create an instance of Payment. • Figure 15.4’s communication diagram tells the same story. • But its connectors’ sequence numbers and arrows allow the blocks to be sketched anywhere. • Thinking about the required messages and their senders’ and receivers’ needs is important in OOD.
15.2-15.3 UML Interaction Notation Figure 15.5 Lifeline boxes show interaction participants. Figure 15.6 Singletons. • As interaction participants, lifeline boxes are named with… • Named or unnamed instances of a class. • Ditto plus their class name. • A named instance of a class that is parameterized (i.e., templatized) to hold another class’ objects. • A numbered instance of the aforementioned class. • A named interface class instance. • The singleton design pattern illustrates the only instance of a class with a ‘1’ in its lifeline box.
15.4 Basic Sequence Diagram Notation Figures 15.7-15.18 Basic sequence diagram notations. • The dashed lifeline broadens into an activation bar to show execution specification (i.e., focus of control, activation bar). Found messages have no specified source. Solid, filled horizontal arrows depict synchronous messages (blocking till response), and open dashed arrows depict asynchronous (non-blocking, threaded) replies. • A nested activation bar depicts an object sending itself a “this” message. • Create an instance by sketching a dashed arrow directly to its named box, and destroy it with an arrow to an X on its dashed lifeline. • A frame labeled “loop” encloses conditionals and looping constructs. Other labels are “alt,” (mutual exclusion), “opt” (conditional), “par” and “region” (table, p.231). A bracketed guard (i.e., conditional clause) prevents execution if false. • An action box can specify a C++ Standard Library iteration over a list. A selector expression (Figure 15.16) tells which object to select. • Of course, frames may be nested, like nested loops in code.
15.4 Basic Seq. Diag. Not. (continued) Figures 15.19-15.22 Basic sequence diagram notations. • A sequence diagram’s “ref” (reference) frame may include another named sequence diagram as an interaction occurrence, which is sketched inside a free-standing “sd” (sequence diagram) frame. • Interaction overview diagrams also exist to gather many reference frames for wide-spread use. • Metaclasses can be declared and invoked, “after drinking some beer” (top p.237). • Several sequence diagrams can work together to model polymorphic messages. • In double vertical line boxes, active objects run continuously in their own threads; e.g., clocks, calendars.
15.5 Basic Comm Diagram Notation Figures 15.23-15.35 Basic sequence diagram notations. • As an instance of an association that connects two object boxes, a linkindicates visibility and navigation. • Multiple bidirectional messages flowing on the same link can be distinguished by their sequence numbers and direction arrows. • Sketching a link in a loop depicts sending a message to one’s self. • The UML stereotype <<create>> message creates instances, and the UML tagged value [new] may optionally be added to its lifeline. • Incoming message sequence numbers get prepended to (nested) outgoing message numbers. (Life is easier if you don’t number the first message.) • A conditional message gets sent, only if its bracketed conditional clause is true. Mutually exclusive messages have opposite conditionals, and their alternate paths can be marked ‘a’ and ‘b’. • Iteration and looping use bracketed do-loop indices; e.g., [i=1..n]. • Communication diagrams invoke metaclasses and handle polymorphism, like sequence diagrams do.
R U O K ? • Interactions diagrams are… __ • Communication diagrams. • Sequence diagrams • UML models of dynamic objects. • Lower-level OO software designers’ aids for thinking about required messages and their senders’ and receivers’ needs. • All of the above. • None of the above.
R U O K ? Identify the following properties of sequence and communication diagrams. 2. Looks like a fence. __ 3. Class-named blocks can be vertically aligned. __ 4. Easier to draw. __ 5. More notation, semantics and tool support. __ 6. Clearer call-flow sequence. __ • Sequence diagram. • Communication diagram.
R U O K ? Match the following terms with their definitions below. 7. interaction participants. __8. Lifelines. __ 9. Singleton design pattern. __10. execution specification. __ 11. Found message.__12. synchronous message.__ 13. asynchronous message. __14. frame. __ 15. action box. __16. selector expression. __ 17. A “this” message. __18. Instance creation. __ a. Solid, filled horizontal arrow depicts a message that blocks while waiting for a response. b. Encloses conditionals and looping constructs. c. A dashed lifeline that broadens into an activation bar to show focus of control. d. The names inside lifeline boxes. e. The only instance of a class has a ‘1’ in its lifeline box. f. Open, dashed arrow depicts a threaded message that does not wait for a reply. g. No specified source. h. Tells which object to select from an iteration. k. Can specify a C++ Standard Library iteration over a list. m. A nested activation bar that depicts an object sending itself a message. n. The dotted line beneath a lifeline box. p. A dashed arrow pointing directly at an instance’ named box.
R U O K ? 19. Which of the following would NOT be a suitable lifeline box’ name? __ • Named or unnamed instance of a class. • Ditto plus their class name. • A class’ attribute or method. • A named instance of a class that is parameterized (i.e., template-ized) to hold another class’ objects. • A numbered instance of the aforementioned class. • A named interface class instance.
R U O K ? Match the following terms with their definitions below. 20. Reference frame. __ 21. Interaction occurrence. __ 22. Interaction overview diagram. __ 23. Metaclass. __ 24. Polymorphic message. __ 25. Active object. __ a. Run continuously in their own threads; e.g., clocks, calendars. b. Gathers many reference frames for wide-spread use. c. A free-standing sequence diagram frame that can be “called” like a sub-function. d. One sequence diagram shows the message to an abstract Metaclass or interface object, and other sequence diagrams detail each case. e. Includes an externally named sequence diagram in this sequence diagram. f. Its instances are classes.
R U O K ? 26. True or false: Many messages may flow in both directions, along a single association-instance link connecting two communication diagram object boxes. __ • True. • False.