interaction diagrams - chapter 15 describe/illustrate sequence of message exchanges among objects...
Post on 19-Dec-2015
220 views
TRANSCRIPT
![Page 1: Interaction Diagrams - Chapter 15 Describe/illustrate sequence of message exchanges among objects show the flow of control across many objects used to](https://reader030.vdocuments.us/reader030/viewer/2022032800/56649d2a5503460f949ff798/html5/thumbnails/1.jpg)
Interaction Diagrams - Chapter 15
Describe/illustrate sequence of message exchanges among objects
•show the flow of control across many objects
•used to illustrate a use case, a scenario, ...
Types
•Collaboration diagram
•Sequence diagram
![Page 2: Interaction Diagrams - Chapter 15 Describe/illustrate sequence of message exchanges among objects show the flow of control across many objects used to](https://reader030.vdocuments.us/reader030/viewer/2022032800/56649d2a5503460f949ff798/html5/thumbnails/2.jpg)
Interaction Diagrams
Message
•asynchronous or synchronous
•components
•numbered (collaboration diagram)
•guard
•name
•parameter list
•name is mandatory ... others as required
![Page 3: Interaction Diagrams - Chapter 15 Describe/illustrate sequence of message exchanges among objects show the flow of control across many objects used to](https://reader030.vdocuments.us/reader030/viewer/2022032800/56649d2a5503460f949ff798/html5/thumbnails/3.jpg)
Interaction Diagrams
• Synchronous vs asynchronous messages
• We will assume (at first) that all messages are synchronous:
• if object A sends a message to object B then A is suspended
• object B gains control, and B begins to compute
• object A waits until B responds (i.e. B sends a message back to A)
•When an asynchronous message is sent from A to B, A does not pause and wait for B to finish … results in multiple threads of control.
![Page 4: Interaction Diagrams - Chapter 15 Describe/illustrate sequence of message exchanges among objects show the flow of control across many objects used to](https://reader030.vdocuments.us/reader030/viewer/2022032800/56649d2a5503460f949ff798/html5/thumbnails/4.jpg)
Interaction Diagrams
Synchronous messages:
•control, or the ability to compute, is gained by holding a token that is passed with a message
• consider that there is an activation stack:
• when object A sends a message to object B, object B goes on to the top of the stack and it can compute. If B responds to A then B is popped from the stack and A, being at the top, begins to compute
![Page 5: Interaction Diagrams - Chapter 15 Describe/illustrate sequence of message exchanges among objects show the flow of control across many objects used to](https://reader030.vdocuments.us/reader030/viewer/2022032800/56649d2a5503460f949ff798/html5/thumbnails/5.jpg)
Collaboration Diagram
•Objects are represented similarly to classes in a class model … relationships are indicated clearly
•Objects may be named or unnamed
•Timing is understood by the numbering scheme. We use a nested decimal numbering to indicate the order in which messages are sent
•Many messages may be sent across one link
![Page 6: Interaction Diagrams - Chapter 15 Describe/illustrate sequence of message exchanges among objects show the flow of control across many objects used to](https://reader030.vdocuments.us/reader030/viewer/2022032800/56649d2a5503460f949ff798/html5/thumbnails/6.jpg)
Figure 15.3 Collaboration diagram for makePayment
![Page 7: Interaction Diagrams - Chapter 15 Describe/illustrate sequence of message exchanges among objects show the flow of control across many objects used to](https://reader030.vdocuments.us/reader030/viewer/2022032800/56649d2a5503460f949ff798/html5/thumbnails/7.jpg)
Figure 15.7 Messages
![Page 8: Interaction Diagrams - Chapter 15 Describe/illustrate sequence of message exchanges among objects show the flow of control across many objects used to](https://reader030.vdocuments.us/reader030/viewer/2022032800/56649d2a5503460f949ff798/html5/thumbnails/8.jpg)
Figure 15.8 Message to ‘this’
![Page 9: Interaction Diagrams - Chapter 15 Describe/illustrate sequence of message exchanges among objects show the flow of control across many objects used to](https://reader030.vdocuments.us/reader030/viewer/2022032800/56649d2a5503460f949ff798/html5/thumbnails/9.jpg)
Figure 15.9 Instance creation
![Page 10: Interaction Diagrams - Chapter 15 Describe/illustrate sequence of message exchanges among objects show the flow of control across many objects used to](https://reader030.vdocuments.us/reader030/viewer/2022032800/56649d2a5503460f949ff798/html5/thumbnails/10.jpg)
Figure 15.10 Sequence Numbering
![Page 11: Interaction Diagrams - Chapter 15 Describe/illustrate sequence of message exchanges among objects show the flow of control across many objects used to](https://reader030.vdocuments.us/reader030/viewer/2022032800/56649d2a5503460f949ff798/html5/thumbnails/11.jpg)
Figure 15.11 Complex numbering
![Page 12: Interaction Diagrams - Chapter 15 Describe/illustrate sequence of message exchanges among objects show the flow of control across many objects used to](https://reader030.vdocuments.us/reader030/viewer/2022032800/56649d2a5503460f949ff798/html5/thumbnails/12.jpg)
Figure 15.12 Conditional Message
![Page 13: Interaction Diagrams - Chapter 15 Describe/illustrate sequence of message exchanges among objects show the flow of control across many objects used to](https://reader030.vdocuments.us/reader030/viewer/2022032800/56649d2a5503460f949ff798/html5/thumbnails/13.jpg)
Figure 15.13 Mutually exclusive messages
![Page 14: Interaction Diagrams - Chapter 15 Describe/illustrate sequence of message exchanges among objects show the flow of control across many objects used to](https://reader030.vdocuments.us/reader030/viewer/2022032800/56649d2a5503460f949ff798/html5/thumbnails/14.jpg)
Figure 15.14 Iteration
![Page 15: Interaction Diagrams - Chapter 15 Describe/illustrate sequence of message exchanges among objects show the flow of control across many objects used to](https://reader030.vdocuments.us/reader030/viewer/2022032800/56649d2a5503460f949ff798/html5/thumbnails/15.jpg)
Figure 15.15 Iteration over a multiobject
![Page 16: Interaction Diagrams - Chapter 15 Describe/illustrate sequence of message exchanges among objects show the flow of control across many objects used to](https://reader030.vdocuments.us/reader030/viewer/2022032800/56649d2a5503460f949ff798/html5/thumbnails/16.jpg)
Figure 15.16 Messages to a class itself, not an object
![Page 17: Interaction Diagrams - Chapter 15 Describe/illustrate sequence of message exchanges among objects show the flow of control across many objects used to](https://reader030.vdocuments.us/reader030/viewer/2022032800/56649d2a5503460f949ff798/html5/thumbnails/17.jpg)
Collaboration Diagram - example
Suppose we have classes for POrder, Customer, LineItem, Product with the following class model
POrder
LineItem Product
Customer1
10..*0..*
1
0..*
We want to exhibit how objects of these classes communicate in order for the POrder to learn its value
![Page 18: Interaction Diagrams - Chapter 15 Describe/illustrate sequence of message exchanges among objects show the flow of control across many objects used to](https://reader030.vdocuments.us/reader030/viewer/2022032800/56649d2a5503460f949ff798/html5/thumbnails/18.jpg)
Collaboration Diagram - example
Suppose
•POrder does not know its value.
•To determine its value it must ask each of its line items “what are you worth?”, and then ask the customer “what discount do you get”.
•Each line doesn’t remember the corresponding products price and so it must interrogate the product to determine the price
POrder
LineItem Product
Customer1
10..*0..*
1
0..*
![Page 19: Interaction Diagrams - Chapter 15 Describe/illustrate sequence of message exchanges among objects show the flow of control across many objects used to](https://reader030.vdocuments.us/reader030/viewer/2022032800/56649d2a5503460f949ff798/html5/thumbnails/19.jpg)
Collaboration Diagram
128937:POrder
line1:LineItem TYZMonitor:Product
line2:LineItem OptMouseX :Product
JonesSupply:Customer
1:cost:=reportTotal()
1.1:price:=reportPrice()
2:reportTotal()
2.1:price:=reportPrice()
3:discount:=reportDiscount()
reportTotal()
Given that the objects below are involved, we show them along with the basic associations
Since these are objects, not classes, there are no multiplicities
Some message starts things off
![Page 20: Interaction Diagrams - Chapter 15 Describe/illustrate sequence of message exchanges among objects show the flow of control across many objects used to](https://reader030.vdocuments.us/reader030/viewer/2022032800/56649d2a5503460f949ff798/html5/thumbnails/20.jpg)
Collaboration Diagram
•Use the diagramming technique to show the complexity you need to understand or represent
•Example: consider the creation of the lines of a Purchase Order, and where
•we are checking for adequate stock on hand•we reorder if we fall below a reorder quantity - a reorder item line is created•if there’s enough on hand, a delivery line item gets created and quantity on hand must be decremented
![Page 21: Interaction Diagrams - Chapter 15 Describe/illustrate sequence of message exchanges among objects show the flow of control across many objects used to](https://reader030.vdocuments.us/reader030/viewer/2022032800/56649d2a5503460f949ff798/html5/thumbnails/21.jpg)
Collaboration Diagram - example
128937:POrder
:LineItem
:DeliveryItem {new}
1*[for all order lines]: prepare()
1.1:reportPrice()1.2:[hasStock]:=remove()
1.2.1:needsToReorder:=needToReorder()
1.2.2:[needsToReorder]:create1.3:[hasStock]:=create
:Product
:ReorderItem {new}