7M822 UML Sequence Diagrams 5 October 2009
7M822 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 Collaboration diagram 2
7M822 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 Collaboration diagram 3
7M822 Behaviour modelling Behaviour models are used to describe the overall behaviour of the system. Objects interact to implement behaviour. This interaction can be described in two complementary ways, one of them is centred on individual objects and the other on a collection of cooperating objects. 4
7M822 from: Fowler & Scott UML distilled, 2 nd edition. 5
7M822 Interaction diagrams Interaction diagrams are models that describe how groups of objects collaborate in some behaviour. Two kinds of interaction diagrams: –sequence diagrams –collaboration diagrams 6
7M822 from: Fowler & Scott UML distilled, 2 nd edition. 7
7M822 Sequence diagram A sequence diagram captures the behaviour of a scenario. The diagram shows a number of objects and the messages that are passed between these objects within the use case. A sequence diagram shows a set of messages arranged in time sequence. 8
7M822 Concepts sequence diagrams 9
7M822 Concepts sequence diagrams elementary message activation synchronic message return lifeline object control guard 10
7M822 Concepts sequence diagrams constraint 11
7M822 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. 12
7M822 Elements sequence diagrams 13
7M822 from: Fowler & Scott UML distilled, 2 nd edition. 14
7M822 from: Fowler & Scott UML distilled, 2 nd edition. 15
7M822 from: Fowler & Scott UML distilled, 2 nd edition. 16
7M822 NS Ticket service Take ticket Destination 17
7M822 Class diagram of ‘NS ticket service’ including the classes ‘Ticket’ and ‘Destination’ 18
7M822 NS Ticket machine – use case text Use Case Buy OV Ticket Actors Traveller Preconditions Traveller has a valid pass Description 1.Ticket device expects destination code 2.Traveller enters destination code 3.Extension point: NS ticket 4.Ticket device checks code and calculates the charge. Shows destination code & fare. Activates ticket machine for paying 5.Traveller pays (use case: Pay ticket) 6.Ticket device print and supplies ticket 7.Traveller takes ticket Extension Destination code = NS station. 3a. Ticket device expects ticket type 3b. Traveller enters Single/Return, Discount Y/N, Class Exceptions Traveller interrupt the interaction or walk away Traveller enters an incorrect destination code Payment is not finished off successful Result Traveller has ticket. (NS can look forward to the payment) 19
7M822 Sequence diagram – Buy ticket 20
7M822 Elevator Example Scenario User pressed floor button Elevator system detects floor button pressed Elevator moves to floor Elevator open doors User gets in and press elevator button Elevator moves to required floor Elevator open doors User gets out Elevator close doors 21