Sequence Diagram Objects are represented horizontally across the top of the diagram The first object is an Actor, the one who initiated the Use Case Each object has a lifeline some exist before and after the Use Case some are created during the Use Case some are destroyed during the Use Case An active object is indicated by a narrow rectangle (on the activation stack) Time is represented vertically down the diagram. Time moves forward as you go downwards
Figure 15.2 Sequence Diagram
Figure 15.4 Sequence diagram
Figure Focus of control
Figure Showing returns
Figure Message to ‘this’
Figure Destroying an object
Figure Conditional message
Figure Mutually exclusive conditional messages
Figure Iteration
Figure Iteration over a sequence of messages
Figure Iteration over a multiobject
Figure Messages to a class itself, not an object
Sequence Diagram - example Check to see if there is enough quantity on hand If there is, then remove that quantity from inventory and create a delivery item for those goods If there is not enough on hand, then create a back order line item We have 4 objects: an orderLine, product, delivery line item, and a back order line item. The delivery line item and back order line item will be created during the scenario
Sequence Diagram - example :OLine:Product 1:hasStock:=checkQOH() 2:[hasStock]remove() :DelItem 3:[hasStock]new() :BOItem 4:[not hasStock]new() Message numbers are not necessary on SD, and are not shown in the text.
Sequence Diagram - example 2 Check the quantity on hand if there is adequate stock, then check for the need to reorder if we need to reorder then create a reorder line item
Sequence Diagram - example 2 :OLine:Product 1:hasStock:=checkQOH() 2:[hasStock] remove() :RItem 2.1:needToReorder:=checkLevel() 2.3:[needToReorder] new()
Sequence Diagram - example 3 For each line of a purchase order check the quantity on hand if there is enough, remove the quantity from inventory
Sequence Diagram - example 3 :OLine:Product 1.1:hasStock:=checkQOH() 1.2:[hasStock] remove() :PO 1:*[for each line] checkQOH()
Sequence Diagram Example Consider the sequence of events: For each line of a purchase order Check the quantity on hand If there is enough, remove that quantity from inventory create a delivery item for those goods check for the need to reorder if we need to reorder then create a reorder line item If there is not enough on hand, then create a back order line item
As a Sequence Diagram :OLine:Product hasStock:=checkQOH() [hasStock] remove() :PO *[for each line] checkQOH() :DelItem :BOItem [hasStock] new() [not hasStock] new() :RItem needToReorder := checkLevel() [needToReorder] new()
As a Collaboration Diagram :POrder :OLine : DelItem {new} 1*[for all order lines] checkQOH() 1.1: hasStock:=checkQOH() 1.2: [hasStock] remove() 1.2.1: needToReorder := checkLevel() 1.2.2:[needToReorder] new() 1.3a: [hasStock] new() :Product :RItem {new} 1.3b: [not hasStock] new() :BOItem {new}