Sequence Diagrams: Interaction Frames Ferd van Odenhoven Fontys - - PowerPoint PPT Presentation

sequence diagrams interaction frames
SMART_READER_LITE
LIVE PREVIEW

Sequence Diagrams: Interaction Frames Ferd van Odenhoven Fontys - - PowerPoint PPT Presentation

Interaction Frames Sequence Diagrams: Interaction Frames Ferd van Odenhoven Fontys Hogeschool voor Techniek en Logistiek May 27, 2015 FvO/FHTBM Sequence Diagrams: Interaction Frames May 27, 2015 1/19 Library Example Interaction Frames


slide-1
SLIDE 1

Interaction Frames

Sequence Diagrams: Interaction Frames

Ferd van Odenhoven

Fontys Hogeschool voor Techniek en Logistiek

May 27, 2015

FvO/FHTBM Sequence Diagrams: Interaction Frames May 27, 2015 1/19

slide-2
SLIDE 2

Interaction Frames Library Example Train planner example

Introduction: exam recap

A simple class diagram about a restaurant was given. The task was to draw the sequence diagramm for the use case: order a meal.

<<facade>> Restaurant makeNewOrder(mealName, nrOfPortions) getNextOrderNumber():orderNumber Order Order(orderNumber) addMeal(mealName, quantity) 1 *

Figure : The class diagram

FvO/FHTBM Sequence Diagrams: Interaction Frames May 27, 2015 2/19

slide-3
SLIDE 3

Interaction Frames Library Example Train planner example

Introduction

Concrete scenario: order 1 pizza ’Peperoni’.

:Restaurant

  • rder:Order

7 getNextOrderNumber() makeNewOrder("Pepperoni",1) addMeal("Pepperoni",1) new Order(7)

Figure : The sequence diagram

FvO/FHTBM Sequence Diagrams: Interaction Frames May 27, 2015 3/19

slide-4
SLIDE 4

Interaction Frames Library Example Train planner example

Java Code Example

package restaurant; public class Restaurant { public void makeNewOrder (String mealName , int nrOfPortions ) { int nr = this. etNextOrderNumber (); Order o = new Order(nr);

  • .addMeal(mealname , nrOfPortions );

} private int getNextOrderNumber () { return 7; } } class Order { private int

  • rderNr;

private Set <String > meals; Order(int

  • rderNr) {

this.nr = orderNr; meals = new HashSet < >(); } void addMeal(String mealName) { this.meals.add(mealName ); } }

FvO/FHTBM Sequence Diagrams: Interaction Frames May 27, 2015 4/19

slide-5
SLIDE 5

Interaction Frames Library Example Train planner example

Interaction Frames

More details: for implementation.

Interaction frames (or fragments) can: show loops and conditional behaviour an interaction frame has an operator and possibly a guard a frame can be divided into one or more fragment’s each of which may have a guard Use an activity diagram if you only want to explain a control structure.

FvO/FHTBM Sequence Diagrams: Interaction Frames May 27, 2015 5/19

slide-6
SLIDE 6

Interaction Frames Library Example Train planner example

An interaction frame (UMLet)

  • ptional [date expired]

lib:Library addPenalty(amount) m1:Account amount calculatePenalty() sd

Figure : A small example

FvO/FHTBM Sequence Diagrams: Interaction Frames May 27, 2015 6/19

slide-7
SLIDE 7

Interaction Frames Library Example Train planner example

Library Example: class diagram

Let’s try to find all the books of a given author, that have copies available. We want to have a list of titles of the books for which copies are available for a rental.

library Book ~getAuthor():String ~getTitle():String ~hasAvailableCOpies:boolean Library +getAvailableTitlesOfAuthor(name):String[*] * books

Figure : This part of the class diagram is relevant for searching a book. We will make a sequence diagram.

FvO/FHTBM Sequence Diagrams: Interaction Frames May 27, 2015 7/19

slide-8
SLIDE 8

Interaction Frames Library Example Train planner example

Library Example: sequence diagram

alt: [available==true] titles:String[*] loop: [for book in books] book:Book :Library alt: [author==name] available hasAvailableCopies() add(title) title getTitle() new titles author getAuthor() getAvailableTitlesOfAuthor(name)

Figure : The sequence diagram shows how interaction frames can be used to show how a loop is to be interpreted.

FvO/FHTBM Sequence Diagrams: Interaction Frames May 27, 2015 8/19

slide-9
SLIDE 9

Interaction Frames Library Example Train planner example

Train planner example

Train line: you don’t have to change trains on your train trip. A train line has an id. Interchange station: a station where you can change the train line.

FvO/FHTBM Sequence Diagrams: Interaction Frames May 27, 2015 9/19

slide-10
SLIDE 10

Interaction Frames Library Example Train planner example

Train planner example: class diagram

«create» 2..* {ordered} * 1 1 TrainTrip stationFrom:String stationT

  • :String

addStation(station:Station Network +findConnection(s1:Station, s2:Station):Station[*] +getTrainLineIdBetween(s1:Station, s2:Station):int ~ findTrainLine(station, nextStation) * InterchangeStation lineCodes:String[*] StartStation departureTime IntermediateStation arrivalTime departureTime EndStation arrivalTime 2..* {ordered} {abstract} Station name:String isInterchangeStation:boolean TrainLine lineCode:String findLineStationsBetween(station,nextStation):Station[*] TrainPlanner createTrainTripFromT

  • (s1:Station,s2:Station):TrainTrip

FvO/FHTBM Sequence Diagrams: Interaction Frames May 27, 2015 10/19

slide-11
SLIDE 11

Interaction Frames Library Example Train planner example

Train planner example: use case diagram

Train Trip Planner Traveller UC1 Create Train Trip UC2 Search Connection «follows»

Figure : Use case diagram for the creation of a train trip. A sub use case (UC2) for finding the connection should be executed first.

FvO/FHTBM Sequence Diagrams: Interaction Frames May 27, 2015 11/19

slide-12
SLIDE 12

Interaction Frames Library Example Train planner example

start sequence diagram

findConnection("Venlo","Moers"):InterchangeStation[*] new TrainTrip() addStation(station) createTrainTrip("Venlo","Moers") loop :TrainPlanner :Network stations :TrainTrip

Figure : Use case 2 is present in method: findConnection(station,station) of the Network class, but without any detail about how it works.

FvO/FHTBM Sequence Diagrams: Interaction Frames May 27, 2015 12/19

slide-13
SLIDE 13

Interaction Frames Library Example Train planner example

Train planner example: Use case

In the train travel planner case we look at a the way a trip could be planned.

Name: UC1: Create a train trip Pre: Systeem staat gereed Description: A train trip from Venlo to Moers has to be planned Result: A orderd row of stations, first one is Venlo, laat one is Moers. Scenario:

  • 1. UC2: A connection is searched from

Venlo to Moers.

  • 2. The system takes as a starting point the first station
  • f the axcahnge stations: Venlo.
  • 3. Search a train connection with code

that is present in Venlo and in Viersen.

  • 4. All simple stations between Venlo and Viersen in the

connection are searched for.

  • 5. Repeat steps 3 and 4 for the next part:

Viersen to Krefeld.

  • 6. If the total connection is treated this way, we have

the total train trip.

FvO/FHTBM Sequence Diagrams: Interaction Frames May 27, 2015 13/19

slide-14
SLIDE 14

Interaction Frames Library Example Train planner example

Train planner: UC2

The following use case is not yet completely described. Name: UC2: Zoek een Verbinding Scenario:

  • 1. Input: two stations
  • 2. Test if both stations are exchange stations.

Result: An ordered row of exchange stations. Extension: If an input station is not an exchange station, seearch the optimal first exchange station. In the UC1 scenario: Venlo → Viersen → Krefeld → KR-Oppum → KR-Uerdingen → Rheinhausen

Moers is not an exchange station

FvO/FHTBM Sequence Diagrams: Interaction Frames May 27, 2015 14/19

slide-15
SLIDE 15

Interaction Frames Library Example Train planner example

On the map

FvO/FHTBM Sequence Diagrams: Interaction Frames May 27, 2015 15/19

slide-16
SLIDE 16

Interaction Frames Library Example Train planner example

On the map

FvO/FHTBM Sequence Diagrams: Interaction Frames May 27, 2015 16/19

slide-17
SLIDE 17

Interaction Frames Library Example Train planner example

On the map

FvO/FHTBM Sequence Diagrams: Interaction Frames May 27, 2015 17/19

slide-18
SLIDE 18

Interaction Frames Library Example Train planner example

Total sequence diagram

addStation(endStation) addStation(startStation) stations:Station[*] findTrainLine(station, nextStation) :TrainPlanner createTrainTrip("Venlo","Moers") new :Network line:TrainLine stations findConnection("Venlo","Moers") :InterchangeStation[*] lineStations findLineStationsBetween(station,nextStation):LineStation[*] :TrainTrip addStation(station) loop [for each station in lineStations] loop [for station in stations] line addStation(station)

FvO/FHTBM Sequence Diagrams: Interaction Frames May 27, 2015 18/19

slide-19
SLIDE 19

Interaction Frames Library Example Train planner example

Interaction Frames: how much detail?

Sequence diagrams: not to the very last detail! Show how a scenario proceeds in main steps. Leave the implementation details to the programmer. The sequence diagram should be a hint for the programmer.

FvO/FHTBM Sequence Diagrams: Interaction Frames May 27, 2015 19/19