Sequence Diagrams Ferd van Odenhoven Fontys Hogeschool voor - - PowerPoint PPT Presentation

sequence diagrams
SMART_READER_LITE
LIVE PREVIEW

Sequence Diagrams Ferd van Odenhoven Fontys Hogeschool voor - - PowerPoint PPT Presentation

Sequence Diagrams Example and Assignment Sequence Diagrams Ferd van Odenhoven Fontys Hogeschool voor Techniek en Logistiek May 27, 2015 FvO/FHTBM Sequence Diagrams May 27, 2015 1/17 Sequence Diagrams Sequence Diagram Elements Example and


slide-1
SLIDE 1

Sequence Diagrams Example and Assignment

Sequence Diagrams

Ferd van Odenhoven

Fontys Hogeschool voor Techniek en Logistiek

May 27, 2015

FvO/FHTBM Sequence Diagrams May 27, 2015 1/17

slide-2
SLIDE 2

Sequence Diagrams Example and Assignment Sequence Diagram Elements CRC-cards

Sequence Diagram

Definition A sequence diagram displays how a use case could evolve using messages between objects / participants. The messages follow the relations between classes in the class diagram. Typically each concrete scenario has its own sequence diagram. If the domain changes, the sequence diagram might have to be altered too!

FvO/FHTBM Sequence Diagrams May 27, 2015 2/17

slide-3
SLIDE 3

Sequence Diagrams Example and Assignment Sequence Diagram Elements CRC-cards

Sequence Diagram Elements

In UML1 the messages are between objects, as of UML2 they are termed more general as participants. In de figure below the participant is an object.

UML 1 UML 2 make reservation :Library make reservation {found message} Note.. Found message: since UML 2 Objects: no underlining in UML2 Member :Library Note.. Object: UML 1 Actor: UML 1 & 2

Figure : Message with actor (uml 1 & 2) or ‘found message’ (uml 2)

FvO/FHTBM Sequence Diagrams May 27, 2015 3/17

slide-4
SLIDE 4

Sequence Diagrams Example and Assignment Sequence Diagram Elements CRC-cards

Sequence Diagram Elements

Participants can be anonymous objects or named objects. On the life line, a bar denotes that a participant is active

book:Book :Book Note.. Named Object Note.. Anonymous Object

Figure : Objects are the participants here.

FvO/FHTBM Sequence Diagrams May 27, 2015 4/17

slide-5
SLIDE 5

Sequence Diagrams Example and Assignment Sequence Diagram Elements CRC-cards

Sequence Diagram Elements

Messages may or may not (if the diagram is unambiguous) have return values. A return message is drawn as a dashed arrow. ‘Self calls’ are messages to itself (this) object.

message name Note.. Message :Library return value book:Book Note.. this is a self call

Figure : Messages with returns and self calls.

FvO/FHTBM Sequence Diagrams May 27, 2015 5/17

slide-6
SLIDE 6

Sequence Diagrams Example and Assignment Sequence Diagram Elements CRC-cards

Sequence Diagram Elements

delete(res) UML 1 UML 2.x new Reservation(copy) res:Reservation new Reservation(copy) delete(res) res:Reservation

Figure : Construction and destruction of Objects.

In case of garbage collection there is no destructor method! Showing only the cross symbol shows that the object is no longer present.

FvO/FHTBM Sequence Diagrams May 27, 2015 6/17

slide-7
SLIDE 7

Sequence Diagrams Example and Assignment Sequence Diagram Elements CRC-cards

CRC-cards

A CRC-card looks as follows : Class: Nr: Responsibilities: Collaborations:

Table : CRC-cards can help in dividing the responsibilities over the relevant classes.

FvO/FHTBM Sequence Diagrams May 27, 2015 7/17

slide-8
SLIDE 8

Sequence Diagrams Example and Assignment Sequence Diagram Elements CRC-cards

Why use CRC-cards for sequence diagrams?

A sequence diagram starts at the right object: the one that has the responsibility to start this use case. If for the next step not this object but another object is responsible, a CRC-cards could provie this information. If the sequence diagram looks awkward: too complicated or messy, redistribute certain responsibilities or change the domain model, alter crc-cards and the new sequence diagram should be better.

FvO/FHTBM Sequence Diagrams May 27, 2015 8/17

slide-9
SLIDE 9

Sequence Diagrams Example and Assignment Library Assignment

Library Example: Usecase

Use Case: Make book lending Actor: Member m1 of the library Precondition: Actor is logged on Description:

  • 1. Actor searches for book with data:

title ‘The Ring 1’ and author ‘Tolkien’

  • 2. Actor activates ‘make rental’
  • 3. System checks if there is a copy available
  • 4. A copy is available and is set to borrowed
  • 5. A new rental has been created
  • 6. New rental is added to rentals of member m1
  • 7. System returns a message: “Rental creation OK.”

Extensions: Exceptions:

FvO/FHTBM Sequence Diagrams May 27, 2015 9/17

slide-10
SLIDE 10

Sequence Diagrams Example and Assignment Library Assignment

Library Class Diagram

<<facade>> Library Reservation startDate endDate Book title author Copy isBorrowed Rental startDate endDate Member id <<create>> 1 * has 1..25 for <<create>> 1 * has 1 * has * 1 for *

  • ffers

1 * has

FvO/FHTBM Sequence Diagrams May 27, 2015 10/17

slide-11
SLIDE 11

Sequence Diagrams Example and Assignment Library Assignment

Facade pattern

FvO/FHTBM Sequence Diagrams May 27, 2015 11/17

slide-12
SLIDE 12

Sequence Diagrams Example and Assignment Library Assignment

CRC-card Library

Class: Library Nr: 1 Responsibilities: Collaborations:

  • Manage accounts and members

Account

  • Manage book catalog

Member

  • Create lending

Book

  • Create and make reservations

Copy Rental Reservation

Table : CRC-card for the Library class

FvO/FHTBM Sequence Diagrams May 27, 2015 12/17

slide-13
SLIDE 13

Sequence Diagrams Example and Assignment Library Assignment

CRC-card Book

Class: Book Nr: 2 Responsibilities: Collaborations:

  • Manage Reservations for this book

Reservation

  • Find member who has

Member a reservation for this book Book

  • Add and remove reservations

Table : CRC-card for the Book class

FvO/FHTBM Sequence Diagrams May 27, 2015 13/17

slide-14
SLIDE 14

Sequence Diagrams Example and Assignment Library Assignment

CRC-card Member

Class: Member Nr: 3 Responsibilities: Collaborations:

  • Manage Rentals for this member

Rental

Table : CRC-card for the Member class

Class: Reservation Nr: 4 Responsibilities: Collaborations:

  • Store member that has this reservation

Member

Table : CRC-card for the Reservation class

FvO/FHTBM Sequence Diagrams May 27, 2015 14/17

slide-15
SLIDE 15

Sequence Diagrams Example and Assignment Library Assignment

Library Sequence Diagram

Found message for every user who can be an actor for this use case. ren1:Rental :Library m1:Member copy1:Copy book:Book add Rental (ren1) set borrowed true copy1 book new Rental (copy1, today) get available copy make today a rental for book: "de Ring 1" by "T

  • lkien" for member m1

search book

FvO/FHTBM Sequence Diagrams May 27, 2015 15/17

slide-16
SLIDE 16

Sequence Diagrams Example and Assignment Library Assignment

Object diagram after creating rental

book:Book copy1:Copy borrowed=true copy3:Copy ren1:Rental m1:Member :Library copy2:Copy

Figure : The object ren1 and the connections to and from this object are

  • new. The library has three copies of the corresponding book.

FvO/FHTBM Sequence Diagrams May 27, 2015 16/17

slide-17
SLIDE 17

Sequence Diagrams Example and Assignment Library Assignment

Train company

Create a first version of a class diagram by introducing a facade class with name : TrainCompany Choose two use-cases you made earlier. Make sequence diagrams for these use cases. Do not add superfluous much details! Only the essentials to understand the sequence of steps. Improve your domain model if necessary and comment on your changes.

FvO/FHTBM Sequence Diagrams May 27, 2015 17/17