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 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 1 Order * Order(orderNumber) addMeal(mealName, quantity) Figure : The class diagram FvO/FHTBM Sequence Diagrams: Interaction Frames May 27, 2015 2/19
Library Example Interaction Frames Train planner example Introduction Concrete scenario: order 1 pizza ’Peperoni’. :Restaurant makeNewOrder("Pepperoni",1) getNextOrderNumber() 7 new Order(7) order:Order addMeal("Pepperoni",1) Figure : The sequence diagram FvO/FHTBM Sequence Diagrams: Interaction Frames May 27, 2015 3/19
Library Example Interaction Frames 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); o.addMeal(mealname , nrOfPortions ); } private int getNextOrderNumber () { return 7; } } class Order { private int orderNr; private Set <String > meals; Order(int orderNr) { 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
Library Example Interaction Frames 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
Library Example Interaction Frames Train planner example An interaction frame (UMLet) sd lib:Library m1:Account optional [date expired] calculatePenalty() amount addPenalty(amount) Figure : A small example FvO/FHTBM Sequence Diagrams: Interaction Frames May 27, 2015 6/19
Library Example Interaction Frames 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 books Library Book * +getAvailableTitlesOfAuthor(name):String[*] ~getAuthor():String ~getTitle():String ~hasAvailableCOpies:boolean 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
Library Example Interaction Frames Train planner example Library Example: sequence diagram :Library book:Book getAvailableTitlesOfAuthor(name) new titles:String[*] loop: [for book in books] getAuthor() author alt: [author==name] hasAvailableCopies() available alt: [available==true] getTitle() title add(title) titles 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
Library Example Interaction Frames 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
Library Example Interaction Frames Train planner example Train planner example: class diagram {abstract} Network Station +findConnection(s1:Station, s2:Station):Station[*] name:String +getTrainLineIdBetween(s1:Station, s2:Station):int isInterchangeStation:boolean ~ findTrainLine(station, nextStation) 1 InterchangeStation 2..* 2..* lineCodes:String[*] * 1 {ordered} TrainPlanner createTrainTripFromT o(s1:Station,s2:Station):TrainTrip EndStation arrivalTime TrainLine * lineCode:String findLineStationsBetween(station,nextStation):Station[*] StartStation departureTime TrainTrip «create» {ordered} stationFrom:String IntermediateStation stationT o:String arrivalTime addStation(station:Station departureTime FvO/FHTBM Sequence Diagrams: Interaction Frames May 27, 2015 10/19
Library Example Interaction Frames Train planner example Train planner example: use case diagram Train Trip Planner UC1 «follows» UC2 Traveller Create Train Trip Search Connection 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
Library Example Interaction Frames Train planner example start sequence diagram :TrainPlanner :Network createTrainTrip("Venlo","Moers") findConnection("Venlo","Moers"):InterchangeStation[*] stations new TrainTrip() :TrainTrip loop addStation(station) 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
Library Example Interaction Frames 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 of 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
Library Example Interaction Frames 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
Library Example Interaction Frames Train planner example On the map FvO/FHTBM Sequence Diagrams: Interaction Frames May 27, 2015 15/19
Library Example Interaction Frames Train planner example On the map FvO/FHTBM Sequence Diagrams: Interaction Frames May 27, 2015 16/19
Library Example Interaction Frames Train planner example On the map FvO/FHTBM Sequence Diagrams: Interaction Frames May 27, 2015 17/19
Library Example Interaction Frames Train planner example Total sequence diagram :TrainPlanner :Network line:TrainLine stations:Station[*] createTrainTrip("Venlo","Moers") findConnection("Venlo","Moers") :InterchangeStation[*] stations addStation(startStation) addStation(endStation) new :TrainTrip loop [for station in stations] addStation(station) findTrainLine(station, nextStation) line findLineStationsBetween(station,nextStation):LineStation[*] lineStations loop [for each station in lineStations] addStation(station) FvO/FHTBM Sequence Diagrams: Interaction Frames May 27, 2015 18/19
Library Example Interaction Frames 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
Recommend
More recommend