www.ddss.arch.tue.nl UML Sequence Diagrams 2 December 2010 7M822 www.ddss.arch.tue.nl UML Diagrams • Structure diagram – – – – – Class diagram Object diagram Component diagram Deployment diagram Package diagram • Behaviour diagram – Use Case diagram – Activity diagram – Interaction diagram • Sequence diagram • Communication diagram 7M822 2 www.ddss.arch.tue.nl In a nutshell: what are interactions? • A collection of communications between instances, including all ways to affect instances, like operation invocation, as well as creation and destruction of instances • The communications are partially ordered (in time) 7M822 3 www.ddss.arch.tue.nl Interaction Diagram Guide • Show interactions between instances in the model – graph of instances (possibly including links) and stimuli – existing instances – creation and deletion of instances • Kinds – Sequence diagram (temporal focus) – Communication diagram (structural focus) 7M822 4 www.ddss.arch.tue.nl Interaction Diagrams Sequence Diagram x y Communication Diagram z 1.1: a 1.2: c x a y b 1.1.1: b c z 7M822 5 www.ddss.arch.tue.nl Different Kinds of Arrows Procedure call or other kind of nested flow of control (synchronous message) Return Asynchronous message Asynchronous message in UML 1.x 7M822 6 www.ddss.arch.tue.nl Lifeline & Messages • The vertical line is called the object’s lifeline. The lifeline represents the object’s life during the interaction. • Each message is represented by an arrow between the lifelines of two objects. • The order in which these messages occur is shown top to bottom. • Each message is labeled at minimum with the message name; also arguments and some control information can be included. • A self-back is a message that an object sends to itself, by sending the message arrow back to the same lifeline. 7M822 7 www.ddss.arch.tue.nl Sequence Diagram / Communication Diagram an Order an Order Line aProduct aCustomer calculatePrice getQuantity participant found message 1: calculatePrice lifeline getProduct 1.5.1: getDiscountInfo 1.4: calculateBasePrice() 1.5: calculateDiscounts() aProduct getPricingDetails an Order aCustomer activation return 1.1: getQuantity() 1.2: getProduct() calculateBasePrice 1.3: getPricingDetails message self-call an Order Line calculateDiscounts aProduct getDiscountInfo 7M822 8 www.ddss.arch.tue.nl Sequence Diagram vs. Communication Diagram • Sequence diagrams are used when you want to look at the behavior of several objects within a single use case. Sequence diagrams are good at showing collaborations among the objects. • Communication diagrams emphasize the data links between the various participants in the interaction. With communication diagrams we can show how the participants are linked together. 7M822 9 www.ddss.arch.tue.nl Elements Sequence Diagrams Participant : Object Participant / Object Lifeline Message Return Activation Message Lifeline Self back Return {} Constraint Comment 7M822 10 www.ddss.arch.tue.nl Next Concepts Sequence Diagrams 1of2 :Computer :PrinterServer :Printer :Queue control guard Print Print(file) [printer available] Print(file) [printer working] Save(file) 7M822 11 www.ddss.arch.tue.nl Next Concepts Sequence Diagrams 2of2 :Computer constraint :PrinterServer :Printer Print Print(file) { Print(file) a b-a < 5 sec b b'-b < 1 sec b' } 7M822 12 www.ddss.arch.tue.nl : Order Entry Window : Order : Order Line : Stock Item SEQUENCE DIAGRAM : Reorder Item : Delivery Item 7M822 13 www.ddss.arch.tue.nl : Transaction : Transaction Coordinator : first Transaction Checker Concurrent Processes and Activations : second Transaction Checker 7M822 14 www.ddss.arch.tue.nl : Transaction : Transaction Coordinator : first Transaction Checker : second Transaction Checker SEQUENCE DIAGRAM: Check Failure 7M822 15 www.ddss.arch.tue.nl Example: A Booking System 7M822 16 www.ddss.arch.tue.nl Use Case Description: Change Flt Itinerary • Actors: traveler, client account db, airline reservation system • Preconditions: Traveler has logged in • Basic course: – Traveler selects ‘change flight itinerary’ option – System retrieves traveler’s account and flight itinerary from client account database – System asks traveler to select itinerary segment she wants to change; traveler selects itinerary segment. – System asks traveler for new departure and destination information; traveler provides information. – If flights are available then … – … – System displays transaction summary. • Alternative course: – If no flights are available then… 7M822 17 www.ddss.arch.tue.nl Sequence Diagram: Change Flight Itinerary Traveler : Booking System Client Account DBMS Airline Reservation System change flight itinerary get customer account get itinerary present itinerary select segment present detailed info update information available flight 7M822 18 www.ddss.arch.tue.nl Collaboration Diagram: Change Flt Itinerary 1: change flight itinerary 5: select segment 7: update information 2: get customer account 3: get itinerary : Booking System 4: present itinerary Traveler 6: present detailed info Client Account DBMS 8: available flight Airline Reservation System 7M822 19