UML Weekend Crash Course⢠- To Parent Directory
UML Weekend Crash Course⢠- To Parent Directory UML Weekend Crash Course⢠- To Parent Directory
Session 16—Modeling the Dynamic View: The Sequence Diagram 173 Reference #4 points to an asynchronous event. Typically, you see events that require some type of response like addItem (did it work or not) or productAvailable (is there any product in stock). But there are times when the event is simply a signal to another object to do something. For example, just a moment ago my wife told me that dinner was ready. Knowing my work habits, she knows better than to expect a response. In Figure 16-3, message 7, you send a message to inventory to reduce the count on the product by the quantity supplied. It is up to inventory to queue the request and take care of it. The place order process is not going to wait. (This makes a good illustration but it is probably not very good design.) Note the difference in the arrows. An asynchronous message uses a stick arrowhead instead of the solid arrowhead used for simple or synchronous messages. Now, take a look at messages 4 and 8. Message 4 starts the operation “addProduct” but the return doesn’t come until message 8. All the messages between 4 and 8 are the messages sent by the Order object while performing the operation “addProduct.” This is another good reason to show the returns. Without the returns explicitly shown in Figure 16-3, it would be possible to interpret the diagram to say that the system first adds the product before it even checks to see if the product is available. Finally, to model object creation, you have a few options. In Figure 16-3, message 1, you see the message Order() pointing to the object lifeline. This is a common coding convention for a constructor (an operation with the same name as the Class), an operation that creates an object. But the Sequence diagram uses an object lifeline that should allow us to represent object creation visually. Figure 16-4 shows two variations using the object lifeline. Bill : Customer Standard form Bill : Customer Also used in modeling tools 1: Order() 2: return order Bill's Order : Order 1: Order() 2: return order Bill's Order : Order Figure 16-4 Two ways of modeling object creation The example on the left is the form explicitly defined by the UML. The creation message (constructor) points directly at the Object. This means that the object icon has to be placed somewhere down the page where the creation actually happens instead of at the top. Using this technique implies that objects at the top of the page already existed when the scenario started. The example on the right is a minor variation where the constructor points to the object lifeline just below the object. But the object is still placed on the diagram at the point in time when it is created, rather than at the top. The goal is to represent the fact that the object did not exist prior to the creation message. The object lifeline literally comes into existence when the creation message is sent, so there is no object lifeline before (above) the creation message. Note Not all tools support either of these techniques, so you may have to use the approach in Figure 16-3.
174 Saturday Afternoon REVIEW The dynamic view includes diagrams designed to illustrate how objects work together. The Sequence and Collaboration diagrams specifically show how objects talk to one another to accomplish a goal of the system, one scenario in a Use Case, or one operation. The Sequence diagram is built around three fundamental elements: the objects, messages, and the object lifeline. The objects represent the participants. The messages represent the communication that they send to one another. The object lifelines allow us to arrange the messages in the proper relative sequence. Messages may be synchronous (requiring a response) or asynchronous (not requiring a response). A simple or synchronous message uses a solid line with a solid arrowhead. The asynchronous message uses a solid line with a stick arrowhead. Both of these message types represent the invocation of an operation on the object they are pointing to. So the name of the message becomes an operation signature with the name, arguments, and return type. The return from or answer to a message uses a dashed line and a line-style arrowhead. The return is simply information, so it is written on the return arrow. A message may be conditional on some prior result. This can be shown using the guard condition notation placed in front of the operation name. An object may be active or inactive at various times in the Sequence diagram. To show that an object is busy, use a narrow vertical rectangle, called an activation bar, on the object lifeline from the time the object becomes active to the time that it stops. An object usually becomes active because it has been asked to do something. It becomes inactive when it is finished with the current task. When an object is deleted or destroyed, the timeline ends and an X marks the termination. QUIZ YOURSELF 1. What does the dynamic view represent (See “Knowing the purpose of Sequence and Collaboration diagrams.”) 2. Where do you place the participating objects in a Sequence diagram (See “Defining the basic notation of the Sequence diagram.”) 3. How does the Sequence diagram show that one object tells another object to do something (See “Defining the basic notation of the Sequence diagram.”) 4. How does the Sequence diagram show that an object is busy (See “Defining the extended notation for the Sequence diagram.”) 5. How does the Sequence diagram show that an object no longer exists (See “Defining the extended notation for the Sequence diagram.”)
- Page 146 and 147: Session 11—The Class Diagram: Agg
- Page 148 and 149: Session 11—The Class Diagram: Agg
- Page 150: Session 11—The Class Diagram: Agg
- Page 153 and 154: 130 Saturday Afternoon or not. Each
- Page 155 and 156: 132 Saturday Afternoon 5. “Any it
- Page 157 and 158: 134 Saturday Afternoon designed to
- Page 159 and 160: 136 Saturday Afternoon Table 12-3 T
- Page 161 and 162: 138 Saturday Afternoon REVIEW The C
- Page 163 and 164: 140 Saturday Afternoon Introducing
- Page 165 and 166: 142 Saturday Afternoon Table 13-1 C
- Page 167 and 168: 144 Saturday Afternoon 28: VendorPr
- Page 169 and 170: 146 Saturday Afternoon 0..* VendorP
- Page 172 and 173: SESSION 14 Modeling the Functional
- Page 174 and 175: Session 14—Modeling the Functiona
- Page 176 and 177: Session 14—Modeling the Functiona
- Page 178: Session 14—Modeling the Functiona
- Page 181 and 182: 158 Saturday Afternoon Table 15-1 T
- Page 183 and 184: 160 Saturday Afternoon Figure 15-1
- Page 185 and 186: 162 Saturday Afternoon More product
- Page 187 and 188: 164 Saturday Afternoon start (merge
- Page 190 and 191: SESSION 16 Modeling the Dynamic Vie
- Page 192 and 193: Session 16—Modeling the Dynamic V
- Page 194 and 195: Session 16—Modeling the Dynamic V
- Page 199 and 200: PART III # Saturday Afternoon Part
- Page 201 and 202: PART IV Saturday Evening Session 17
- Page 203 and 204: 180 Saturday Evening Scenario 1 Get
- Page 205 and 206: 182 Saturday Evening The next step
- Page 207 and 208: 184 Saturday Evening For Scenario 2
- Page 209 and 210: 186 Saturday Evening For subsequent
- Page 211 and 212: 188 Saturday Evening 6:addProduct(c
- Page 213 and 214: 190 Saturday Evening 7:addProduct(c
- Page 215 and 216: 192 Saturday Evening REVIEW The Col
- Page 217 and 218: 194 Saturday Evening Scenario 1 Get
- Page 219 and 220: 196 Saturday Evening pointing towar
- Page 221 and 222: 198 Saturday Evening :OrderFullfill
- Page 223 and 224: 200 Saturday Evening Scenario 5, in
- Page 226 and 227: SESSION 20 Modeling the Dynamic Vie
- Page 228 and 229: Session 20—Modeling the Dynamic V
- Page 230 and 231: Session 20—Modeling the Dynamic V
- Page 232 and 233: Session 20—Modeling the Dynamic V
- Page 234: Session 20—Modeling the Dynamic V
- Page 238 and 239: Part V — Sunday Morning Session 2
- Page 240 and 241: SESSION 21 Applying the Basic State
- Page 242 and 243: Session 21—Applying the Basic Sta
- Page 244 and 245: Session 21—Applying the Basic Sta
Session 16—Modeling the Dynamic View: The Sequence Diagram 173<br />
Reference #4 points to an asynchronous event. Typically, you see events that require some<br />
type of response like addItem (did it work or not) or productAvailable (is there any product<br />
in stock). But there are times when the event is simply a signal to another object to do<br />
something. For example, just a moment ago my wife told me that dinner was ready. Knowing<br />
my work habits, she knows better than to expect a response. In Figure 16-3, message 7, you<br />
send a message to inventory to reduce the count on the product by the quantity supplied. It<br />
is up to inventory to queue the request and take care of it. The place order process is not<br />
going to wait. (This makes a good illustration but it is probably not very good design.)<br />
Note the difference in the arrows. An asynchronous message uses a stick arrowhead<br />
instead of the solid arrowhead used for simple or synchronous messages.<br />
Now, take a look at messages 4 and 8. Message 4 starts the operation “addProduct” but<br />
the return doesn’t come until message 8. All the messages between 4 and 8 are the messages<br />
sent by the Order object while performing the operation “addProduct.” This is another good<br />
reason to show the returns. Without the returns explicitly shown in Figure 16-3, it would be<br />
possible to interpret the diagram to say that the system first adds the product before it<br />
even checks to see if the product is available.<br />
Finally, to model object creation, you have a few options. In Figure 16-3, message 1, you<br />
see the message Order() pointing to the object lifeline. This is a common coding convention<br />
for a constructor (an operation with the same name as the Class), an operation that creates<br />
an object. But the Sequence diagram uses an object lifeline that should allow us to represent<br />
object creation visually. Figure 16-4 shows two variations using the object lifeline.<br />
Bill : Customer<br />
Standard form<br />
Bill : Customer<br />
Also used in<br />
modeling tools<br />
1: Order()<br />
2: return order<br />
Bill's Order : Order<br />
1: Order()<br />
2: return order<br />
Bill's Order : Order<br />
Figure 16-4 Two ways of modeling object creation<br />
The example on the left is the form explicitly defined by the <strong>UML</strong>. The creation message<br />
(constructor) points directly at the Object. This means that the object icon has to be placed<br />
somewhere down the page where the creation actually happens instead of at the top. Using<br />
this technique implies that objects at the top of the page already existed when the scenario<br />
started.<br />
The example on the right is a minor variation where the constructor points to the object<br />
lifeline just below the object. But the object is still placed on the diagram at the point in<br />
time when it is created, rather than at the top.<br />
The goal is to represent the fact that the object did not exist prior to the creation message.<br />
The object lifeline literally comes into existence when the creation message is sent, so<br />
there is no object lifeline before (above) the creation message.<br />
Note<br />
Not all tools support either of these techniques, so you may have to use the<br />
approach in Figure 16-3.