UML Weekend Crash Course™ - To Parent Directory

UML Weekend Crash Course™ - To Parent Directory UML Weekend Crash Course™ - To Parent Directory

crnarupa.singidunum.ac.rs
from crnarupa.singidunum.ac.rs More from this publisher
01.01.2015 Views

Session 18—Modeling the Dynamic View: The Collaboration Diagram 191 7. Comment: Reference 7 shows one way that you can reveal your intention to repeat a set of messages. As with Sequence diagrams, comments can be very helpful for explaining your intentions regarding iteration across a set of messages because the iteration notation provided by the UML works only for a single event. Now I’ll change a few items on the diagram so that you can see some new notations. The following descriptions refer to the numbered items in Figure 18-4. 9: Bill: Customer 1 1:Order() 3:addItem(characters) 10:cancel() Bill’s Order : Order 2:return Order 8:return 11:return 5:return product available 7:addProduct(characters) 2 4:productAvailable(characters) 6:[product available] reduceInventory(product #, qty) :Inventory Figure 18-4 More Collaboration diagram notation Note the following items on the diagram: 1. Timeout event: I haven’t labeled this message, mostly because a timeout would be a bit unusual for this type of scenario. This way you get to see the notation anyway. Actually, this is a common extension to the UML (that is, it isn’t explicitly defined by the UML). The small circle represents a clock and sometimes even shows the clock hands within the circle. A timeout would be used for something like dialing into a network or polling a node on a network. If you don’t get a response within a specified amount of time, you abandon the attempt and move on. In this case, if the Order doesn’t respond within the specified time limit, the Order is cancelled in step 10. 2. Asynchronous message: An asynchronous message does not require a reply. Step 6 has been altered to simply tell the Inventory, “I’ve taken some of your stock. You might want to update your records. But I’m not going to wait around until you do.”

192 Saturday Evening REVIEW The Collaboration diagram models pretty much the same information as a Sequence diagram, interactions between objects. It is the perspective that is different. The Collaboration diagram views interactions relative to the structure of the objects and their relationships (links) with one another. The Sequence diagram focuses on timing. Consequently, the advantage of the Collaboration diagram is that it can help you validate the associations between classes or even discover the need for new associations. The Collaboration diagram is built on top of an Object diagram. 1. Place the participating objects on the diagram. 2. Draw the links between the objects using the Class diagram as your guide. 3. Add each event. Place the message arrow parallel to the link between the two objects. Position the arrow to point from the sender to the receiver. 4. Number the messages in order of execution. 5. Repeat steps 3 and 4 until the entire scenario has been modeled. QUIZ YOURSELF 1. How are the participating objects represented in a Collaboration diagram (See “Collaboration Diagram Notation.”) 2. How do you know whether a message may be sent from one particular object to another (See “Diagram differences.”) 3. The Sequence diagram uses a timeline to show the order of messages. What do you use on a Collaboration diagram (See “Collaboration Diagram Notation.”) 4. What is a synchronous message (See “Collaboration Diagram Notation.”) 5. What is an asynchronous message (See “Collaboration Diagram Notation.”)

Session 18—Modeling the Dynamic View: The Collaboration Diagram 191<br />

7. Comment: Reference 7 shows one way that you can reveal your intention to repeat<br />

a set of messages. As with Sequence diagrams, comments can be very helpful for<br />

explaining your intentions regarding iteration across a set of messages because the<br />

iteration notation provided by the <strong>UML</strong> works only for a single event.<br />

Now I’ll change a few items on the diagram so that you can see some new notations. The<br />

following descriptions refer to the numbered items in Figure 18-4.<br />

9:<br />

Bill:<br />

Customer<br />

1<br />

1:Order()<br />

3:addItem(characters)<br />

10:cancel()<br />

Bill’s Order :<br />

Order<br />

2:return Order<br />

8:return<br />

11:return<br />

5:return product available<br />

7:addProduct(characters)<br />

2<br />

4:productAvailable(characters)<br />

6:[product available]<br />

reduceInventory(product #, qty)<br />

:Inventory<br />

Figure 18-4 More Collaboration diagram notation<br />

Note the following items on the diagram:<br />

1. Timeout event: I haven’t labeled this message, mostly because a timeout would be<br />

a bit unusual for this type of scenario. This way you get to see the notation anyway.<br />

Actually, this is a common extension to the <strong>UML</strong> (that is, it isn’t explicitly<br />

defined by the <strong>UML</strong>). The small circle represents a clock and sometimes even shows<br />

the clock hands within the circle. A timeout would be used for something like<br />

dialing into a network or polling a node on a network. If you don’t get a response<br />

within a specified amount of time, you abandon the attempt and move on. In this<br />

case, if the Order doesn’t respond within the specified time limit, the Order is cancelled<br />

in step 10.<br />

2. Asynchronous message: An asynchronous message does not require a reply. Step 6<br />

has been altered to simply tell the Inventory, “I’ve taken some of your stock. You<br />

might want to update your records. But I’m not going to wait around until you do.”

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!