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 189 across. On a Sequence diagram there is nothing stopping you from drawing an arrow between two objects when there is no corresponding link. But doing so would model a logical interaction that cannot physically take place. You can take the opposite view that drawing a message where there is no link reveals the requirement for a new link. Just make certain that you actually update your Class diagram or, as I said before, you won’t be able to implement the message illustrated on the diagram. An advantage of the Sequence diagram is its ability to show the creation and destruction of objects. Newly created objects can be placed on the timeline at the point where they are created. The large X at the end of a timeline shows that the object is no longer available for use. Sequence diagrams also have the advantage of showing object activation. Because the Collaboration diagram does not illustrate time, it is impossible to indicate explicitly when an object is active or inactive without interpreting the types of messages being passed. Collaboration Diagram Notation The Collaboration diagram uses an Object diagram as its foundation. First, determine which objects will participate in the scenario. Draw the objects with only the name compartment, not the attributes. Then draw the links between them. Because any pair of classes can have more than one association, you need to use the Class diagram as your guide to identify the valid types of links that apply to the current sequence of messages. Figure 18-2 shows the objects and their links. You may leave the link names off of the links when there is only one type of association between the related classes. Add the names if there is more than one kind of link possible between the two objects and there is a need to clarify which relationship supports the interaction. Bill: Customer Bill’s Order : Order :Inventory Figure 18-2 Basic Collaboration diagram notation For each step of the scenario, draw the message arrow from the sending object to the receiving object. Place the message arrow parallel to the link between the sending and receiving objects. Having many messages placed on the same link is valid and, in fact, common as long as they really share the same message (arrow) type. Number the messages in the order in which they occur. The format for specifying a message is the same as on the Sequence diagram: Sequence-number Iteration : [condition] operation or return Figure 18-3 models the entire scenario for creating an order. I have added a few twists to the original in Figure 18-1 so that I can demonstrate all the notations.

190 Saturday Evening 7:addProduct(characters) 1 Bill: Customer 1:Order() 3:addItem(characters) 2 2:return Order 8:return true 5:return product available 3 Bill’s Order : Order 4 5 4:productAvailable(characters) 6:[product available] reduceInventory(product #, qty) 7 *Repeat steps 3 through 7 for each item the customer wants to add 6 :Inventory Figure 18-3 More detailed Collaboration diagram notation The following descriptions refer to the numbered items in Figure 18-3 so that you can see the notations used in context: 1. Object: This is a fully qualified object name, Bill, of the class Customer. The notation is exactly the same as on the Sequence diagram. 2. Synchronous event or procedure call: A synchronous event is a message that requires a reply, so you would expect to see a corresponding return message along the same link sometime later in the sequence. Procedure calls are simply another familiar way to describe this “ask and reply” form of interaction. 3. Return: Here is the return message for the message 1. Message 1 told the Order class to create a new Order object, Bill’s Order. When the task of creating the object is completed, it passes back a reference to the requestor, Bill. 4. Self-reference: A self-reference is simply an object talking to itself saying something like, “It’s time for me to get more coffee.” In Figure 18-3, the Order is telling itself to use the item information from step 3 to add another product to its list of items. 5. Sequence number: Because the Collaboration diagram has no way of showing the passage of time, it uses sequence numbers, like (4: ), to reveal the order of execution for the messages. There are no standards for the numbering scheme, so common sense and readability are your guides. The sequence numbers were optional on the Sequence diagram. They are required on the Collaboration diagram. 6. Anonymous object: Reference 6 shows another example of valid object notation. You do not have to name the instance if all you need to convey is that any object of this type (Inventory) would behave in this manner.

190<br />

Saturday Evening<br />

7:addProduct(characters)<br />

1<br />

Bill:<br />

Customer<br />

1:Order()<br />

3:addItem(characters)<br />

2<br />

2:return Order<br />

8:return true<br />

5:return product available<br />

3<br />

Bill’s Order :<br />

Order<br />

4<br />

5<br />

4:productAvailable(characters)<br />

6:[product available]<br />

reduceInventory(product #, qty)<br />

7<br />

*Repeat steps 3 through<br />

7 for each item the<br />

customer wants to add<br />

6<br />

:Inventory<br />

Figure 18-3 More detailed Collaboration diagram notation<br />

The following descriptions refer to the numbered items in Figure 18-3 so that you can see<br />

the notations used in context:<br />

1. Object: This is a fully qualified object name, Bill, of the class Customer. The notation<br />

is exactly the same as on the Sequence diagram.<br />

2. Synchronous event or procedure call: A synchronous event is a message that<br />

requires a reply, so you would expect to see a corresponding return message along<br />

the same link sometime later in the sequence. Procedure calls are simply another<br />

familiar way to describe this “ask and reply” form of interaction.<br />

3. Return: Here is the return message for the message 1. Message 1 told the Order<br />

class to create a new Order object, Bill’s Order. When the task of creating the<br />

object is completed, it passes back a reference to the requestor, Bill.<br />

4. Self-reference: A self-reference is simply an object talking to itself saying something<br />

like, “It’s time for me to get more coffee.” In Figure 18-3, the Order is telling<br />

itself to use the item information from step 3 to add another product to its list of<br />

items.<br />

5. Sequence number: Because the Collaboration diagram has no way of showing the<br />

passage of time, it uses sequence numbers, like (4: ), to reveal the order of execution<br />

for the messages. There are no standards for the numbering scheme, so common<br />

sense and readability are your guides. The sequence numbers were optional on the<br />

Sequence diagram. They are required on the Collaboration diagram.<br />

6. Anonymous object: Reference 6 shows another example of valid object notation.<br />

You do not have to name the instance if all you need to convey is that any object<br />

of this type (Inventory) would behave in this manner.

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

Saved successfully!

Ooh no, something went wrong!