UML behavior diagrams Kristian Sandahl Maintenance Validate Requirements, Verify Specification Acceptance Test Requirements (Release testing) Verify System Design System Design System Testing (Architecture, High-level Design) (Integration testing of modules) Module Design (Program Design, Detailed Design) Verify Module Design Module Testing (Integration testing of units) Verify Implementation Implementation of Units (classes, procedures, functions) Unit testing Project Management, Software Quality Assurance (SQA), Supporting Tools, Education 2 The goals of module design, again • Provide the expected function • Prepare for change: • Separation of concern • Testability • Understandability • Contribute to quality, eg: • Performance • Usability • Reliability • ... • Map for the implementers and testers 3 Well-known Diagrams of UML UML 2.5 Diagram Structure Diagram Class Diagram Object Diagram Behavior Diagram Package Diagram Component Diagram Deployment Diagram 4 Use-Case Diagram State Machine Diagram Interaction Diagram Sequence Diagram Well-known Diagrams of UML UML 2.5 Diagram Structure Diagram Class Diagram Object Diagram Behavior Diagram Package Diagram Component Diagram Deployment Diagram 5 Use-Case Diagram State Machine Diagram Interaction Diagram Sequence Diagram Different instance models Specific Kristian : CoffeeCustomer Generic aCoffeeCustomer : CoffeeCustomer buys buys Cup1 : CupOfCoffee aCup : CupOfCoffee makes IDA-B-house : Machine makes aMachine : Machine makes : Machine makes : Machine Short hand : CoffeeCustomer buys : CupOfCoffee Related: Roles : CoffeeCustomer buys : CupOfCoffee State machine diagram For class CoinHandler: start state marker transiton this object checking falseCoin()/returnCoin(self) idle insertCoin()/checkCoin(self) state trigger event, causing transition action, reaction to the event 7 A few more states Kristian’s alarm clock starts sounding at 6.00 with a nasty signal. He can now do either of three things: Turn the alarm off; b) Press the snooze button; or c) Do nothing. If the snooze button is pressed the signal will turn off and start sounding after 5 minutes again. When an hour has passed from the first time the alarm sound started, the snooze button has no effect. After that the alarm sound starts, the signal will last for 2 minutes. If no action has been taken during these 2 minutes, the absence of action will have the same effect as if the snooze button were pressed exactly when the alarm stopped to sound. a) 8 Orthogonal, composite states state machine course attempt orthogonal state Studying Lab 1 Project Final exam fail orthogonal region lab1 done Lab 2 lab2 done project done pass Failed 9 Passe d Explicit exit points course attempt Studying Lab 1 Project Final exam lab1 done Lab 2 lab2 done project done pass fail failed passed 10 Activity diagram ≠ State diagram Initial node insert coin decision final [no] node coin accepted? fork [yes] brew coffee add hot water to adjust strength add sugar/whitener join pour coffee 11 Sequence diagram role : Interface Message (synchronous) : CoffeeCustomer insertCoin Life line of object machineReady Procedure is active pressButton(b1) time pourCoffee 12 Sequence diagram with several objects : Interface : CoinHandler : Brewer : CoffeeCustomer insertCoin Timing constraint Return message transport { 0 < 5s} litIndicators pressButton(b1) pourCoffee coinAccepted makeOrder(o1) pourCoffee 13 warmUp Combining fragments of sequence diagrams SD processOrder :Order :TicketDB :Account create ref gate Get existing customer data loop loop [get next item] reserve(date,no) loop condition add(seats) answer destruction 14 Combining fragments of sequence diagrams SD Get existing customer data :Order create :TicketDB :Account Getdata(c1) Data(c1) 15 Combining fragments of sequence diagrams SD processOrder :Order :TicketDB :Account create ref Get existing customer data loop loop [get next item] reserve(date,no) loop condition add(seats) answer destruction 16 More fragments of sequence diagrams :Order :TicketDB loop [get next item] reserve(date,no) alt guard condition nested conditional [available] add(seats) alternate branches reject [unavailable] 17 http://www.uml-diagrams.org 18 www.liu.se