Sequence diagrams capture the step-by-step sequence of events in a single use-case scenario. They should capture the essense of user-interaction and document the response for interesting scenarios, involve only major objects/actors.

1.Lecture 13 – Sequence Diagrams Describe the purpose of sequence diagrams Identify the components of a sequence diagram Discuss differences between sequence diagrams used during the analysis phase vs design phase Draw a sequence diagram for a given use case scenario Include loops and conditionals in a sequence diagram Convert a sequence diagram into a class diagram Learning Goals © Paul Davies, C. Antonio Sanchez. Not to be copied, used, or revised without explicit written permission from the copyright owner.

2.Sequence Diagrams Sequence diagrams capture the step-by-step sequence of events in a single use-case scenario . They should capture the essense of user-interaction and document the response for interesting scenarios, involve only major objects/actors. Sequence Diagrams 2 Initiating Actor Participants (objects, actors, roles) Time Message Return Lifeline Activation

3.Sequence Diagrams Sequence Diagrams 3 Participants are usually objects, can be labelled using name : class syntax. Messages can either be descriptive, or methods using the name (arguments) syntax

4.Sequence Diagrams: Analysis vs Design Sequence Diagrams 4 Sequence diagrams are often drawn at two different times during the software-development cycle: during the analysis phase, and the design phase. During analysis phase , useful for communication with the customer, minimal technical/implementation details. Helps to ensure understanding of the process. Often describes an existing (perhaps manual) system. During design phase , includes more implementation specifics . Can be translated into software objects/class diagrams.

5.Example: Analysis Model for Elevator Sequence Diagrams 5 Optional comments:

6.Sequence Diagrams: Message Types Sequence Diagrams 6 End of Life

7.Class Example: Withdraw Cash Create a Sequence Diagram for the following use-case scenario Sequence Diagrams 7 Use Case Withdraw cash The user inserts their bank card into the card reader of the ATM The system reads the chip to identify user & account . The system contacts the bank to request the PIN number for the card and account details. The system prompts the user to enter their PIN . The user enters their PIN. The system prompts for the amount of the cash withdrawal. The user enters the amount of the cash withdrawal. The system checks with the banks central computer to ensure sufficient funds The cash is dispensed and the customer’s account at the bank is debited The card is returned to the user End

8.Sequence Diagrams: Decisions/Iterations Sequence diagrams are not flowcharts. They are more useful when looking at sequences of events and timings . Sequence Diagrams 8 When loops/decisions are important, we can include them combination fragments . Opt Optional fragment that executes if ( Condition) is true . Alt Alternative fragment for mutually exclusive logic based on if-else type decision. Loop Loop fragment: A sequence of messages that repeats while some Condition is true . ( Note : Can also be written as loop(n) to indicate looping n times) Par Two or more sequences that execute in parallel . Region Critical region . A sequence of statements that can only be executed by one thread at a time, the implication is that the designer will have to implement some form of mutual exclusion (i.e. a mutex with wait and signal ) to protect the code.

9.Sequence Diagrams 9 Sequence Diagrams: Decisions/Iterations

10.Sequence Diagrams 10 Sequence Diagrams: Decisions/Iterations

11.Class Example: Withdraw Cash Sequence Diagrams 11

12.Sequence Diagrams: Incoming/Outgoing Sequence Diagrams 12 Lost and found messages are for when the other participant is unknown, or we don’t care for the purposes of this diagram. Gates usually connect to other sequence diagrams which have corresponding games with the same names. Gates

13.Sequence Diagrams: Hierarchies Sequence Diagrams 13 https://knowhow.visual-paradigm.com/uml/sequence-diagram-gate/

14.Sequence Diagrams to Class Diagrams Sequence Diagrams 14 Section from a Sequence Diagram Class Diagram Sequence diagrams and Class Diagrams must be consistent . Messages usually correspond to operations, direction of arrows corresponds to direction of association .

15.Sequence Diagram to Class Diagram Sequence Diagrams 15 Maps to this Class Diagram Section from a Sequence Diagram 2 class Student { Course *course1 ; // points at runtime to EECE314 Course *course2 ; // points at runtime to EECE310 . . . } ; class Course { Student *theStudent ; // points to ‘fred’ at runtime . . . } ;