01.01.2015 Views

UML Weekend Crash Course™ - To Parent Directory

UML Weekend Crash Course™ - To Parent Directory

UML Weekend Crash Course™ - To Parent Directory

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Session 16—Modeling the Dynamic View: The Sequence Diagram 171<br />

5. Return<br />

6. Anonymous object<br />

7. Object name<br />

8. Sequence number<br />

9. Condition<br />

10. Basic comment<br />

The sequence numbers are optional but are very helpful when you need to discuss the<br />

diagram and make changes. Each message arrow describes an interface/operation on the<br />

object it is pointing to. Consequently, the message contains the operation signature, that is,<br />

the name, arguments, and optionally the return, such as addItem(product):boolean.<br />

The dashed return arrows pointed to by references #2 and #5 each contain only the<br />

answer to a message. Some folks leave these off. But the purpose of modeling is to reveal<br />

information, not make assumptions. Showing the returns can help ensure that what you’re<br />

getting back is consistent with what you asked for in the message.<br />

Figure 16-2, reference #3, shows how you can indicate that an operation should be performed<br />

repeatedly. Use the square condition brackets to enclose either the number of times<br />

or the condition that controls the repetitions, for example [for each product].<br />

The same condition brackets may be used to control whether a message is even sent.<br />

Reference #9 points to step 6, which uses the test [product available = yes] to make certain<br />

that the previous step succeeded before performing the operation in step 6.<br />

Reference #10 shows how you may use a <strong>UML</strong> comment to add information that is not<br />

explicitly part of the notation.<br />

Defining the extended notation for the Sequence diagram<br />

Sequence diagrams can be enhanced to illustrate object activation and object termination<br />

and to customize messages.<br />

Figure 16-3 includes some changes to the original Sequence diagram in order to illustrate<br />

these new features. <strong>To</strong> show that an object is active, the notation is to widen the vertical<br />

object lifeline to a narrow rectangle, as shown in Figure 16-3. The narrow rectangle is called<br />

an “activation bar” or “focus of control.” Reference #1 shows when the object becomes<br />

active at the top of the rectangle. Note that the object becomes active when it begins to do<br />

work. Reference #2 shows when the object is deactivated or finishes its work and waits for<br />

the next request. Using this notation, we can see that the Inventory object is only active<br />

while it is responding to the “productAvailable” inquiry, and the Order is activated more<br />

than once: once to create the Order object and once each time it is asked by Bill to perform<br />

“addItem.”<br />

<strong>To</strong> show that an object is terminated, place an X at the point in the object lifeline when<br />

the termination occurs. This is usually in response to a message such as delete or cancel.<br />

See message 10: cancel() followed by the X at reference #5. The absence of the X on an<br />

object lifeline means that the object lives on after this sequence of events is ended.

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

Saved successfully!

Ooh no, something went wrong!