CPSC 491 UML Sequence s UML Sequence s One of many UML notations for modeling behavior A specific type of interaction diagram In this case, the behavior of a single scenario Usually a single call on an object Where the call involves interactions That is, more calls on other objects (Can also include multiple initial calls )
UML Sequence s For example: Calculate the price of an order Get the product prices of the order Determine customer discounts Get shipment costs and so on Sequence diagrams are a similar to drawing function call (or activation) stacks Simple Example of a UML Sequence More generally participants in the sequence diagram Objects Object lifelines
Simple Example of a UML Sequence The first message Doesn t have a participant that sent it The activation bar of () Shows when the operation is active in the interaction (on the call stack) Simple Example of a UML Sequence () calls on the aproduct object A message
Simple Example of a UML Sequence getdiscounts() getdiscounts() is then called on the acustomer object Simple Example of a UML Sequence getdiscounts() getshippinglocation() getshippinglocation() is then called on the acustomer object zipcode Here we show that the message returns a zipcode
Simple Example of a UML Sequence getdiscounts() getshippinglocation() zipcode Finally, the shipping cost is determined from the Product (based on the zipcode) getshippingcost(zipcode) Details: Self calls You can show calls on the object itself ( self-calls ) acustomer : Customer getshippinglocation() getzipcode()
Details: Participant Creation/Deletion You can show object construction / destruction acart : ShoppingCart addtocartandcheckout() new addproduct(p) anorder : Order placeorder() saveorder() close Details: Control-Flow Often it is nice to show (some) control-flow Iteration, Conditionals A general observation Not what sequence diagrams are good at Often better to use a different type of diagram or just write the code (or psuedocode) There are two ways to show control-flow Interaction frames (a newer UML 2 construct) Iteration markers and guards (UML 1)
Interaction Frames: Loops anorder : Order Guard aproduct : Product Interaction frame loop [foreach product] etc. Interaction Frames: Alternatives anorder : Order aproduct : Product loop [foreach product] alt [if price > 1000] usespecialshipping() [else] usestandardshipping() Guards
Interaction Frames Common operators for interaction frames alt opt par loop neg choose from alternative fragments (if-else) do optional fragment if condition holds (if-then) execute each fragment in parallel execute fragment multiple times based on guard the fragment shows an invalid (negative) interaction Iteration markers and guards ( old syntax) anorder : Order aproduct : Product Iteration marker * * [foreach product] This approach is more widely used Alternative [if price > 1000] usespecialshipping() [else] usestandardshipping() Guard Guard
UML Sequence s Good for 1. Showing basic calls between objects 2. Showing what role objects play in the interaction 3. Determining needed operations of objects and why 4. Going from stories to designs Exercise Sketch a sequence diagram for your project Start from a user story Pick operations with interactions among classes Draw at least two sequence diagrams for some interesting behavior of your system