Interaction diagram

advertisement
Notes: 008 – Introduction to Interaction Diagrams
CS/SE3430 / CS5430 - Object-Oriented Analysis and Design
1 (Class) Interaction diagram

Class Diagrams are static representations of a system. They only show the relationship among
classes.

Interaction Diagrams show the order of message flow between Classes.

A Sequence Diagram is one kind of Interaction Diagram. It shows both the order and timing of
messages passed between Classes. The timings can be very important for real-time systems as
it allows time budgeting for each process.

One place to get the message flow is from our Use Cases Scenarios.

Interaction diagrams can be at either Analysis or Design level.
o Design Level uses Objects and Function calls.
o Analysis level uses object concepts and not necessarily the actual function calls.
© 2011 Mike Rowe
Page 1
2/8/2016 4:47:00 PM
Notes: 008 – Introduction to Interaction Diagrams
CS/SE3430 / CS5430 - Object-Oriented Analysis and Design
1.1 Sequence Diagrams
Object :: of class
theCopy : : Copy
aMember : :
BookBorrower
theBook : : Book
theLibraryMember
: : LibraryMember
Borrow(theCopy)
1: okToBorrow
2: Borrow
2.1: Borrowed
Activation Bar
Lifeline
Design-level Sequence Diagram. Note that real object names and function calls are used. In an
Analysis-level Sequence Diagram we would not need to use function names for messages.
Important components of Sequence Diagram:
 Lifeline: Starts when an Object is created and stops when it is destroyed.

Activation Bar: Show the point at which the object is processing and stops when an object goes
idle. May have multiple activation bars on a Lifeline.

Message Arc: shows the direction of the call and the arc label specifies the name of the
interface method. The Arrow indicates the direction of the flow. Between aMember uses the
public interface of the LibraryMember Class to make a request to borrow a book. The Message
Arc labeled okToBorrow would probably be a private method of LibraryMember.

The Sequence diagram is a view of the system just like the Class diagram is a view of the
system. When we produce a Sequence diagram in Rose we want to make sure that we are
using the names (classes and methods) from the Class diagram. Failure to do this will result in
some really goofy behavior in your sequence diagram.
© 2011 Mike Rowe
Page 2
2/8/2016 4:47:00 PM
Notes: 008 – Introduction to Interaction Diagrams
CS/SE3430 / CS5430 - Object-Oriented Analysis and Design
Example 2: Analysis Level Sequence Diagram of Reserve Library Book Checkout
1. Customer presents a library card and book request to a librarian.
2. The Librarian checks to see if the library card is valid (manual inspection).
3. If the card is valid, the catalogue is checked to see if the book is available.
4. Catalogue sends acknowledgement of availability
5. If the book is available, the book location is retrieved from the catalogue.
6. Book location sent back to librarian
7. The librarian fetches the book from Bookshelf
8. Librarian checks out book via catalogue
9. Catalogue acknowledges check out with librarian
10. Librarian releases book to customer.
11. When the customer is done using the book it is returned to a librarian.
12. The librarian checks in the book with the catalogue
13. Catalogue acknowledges check in.
14. Librarian returns book to shelf
© 2011 Mike Rowe
Page 3
2/8/2016 4:47:00 PM
Notes: 008 – Introduction to Interaction Diagrams
CS/SE3430 / CS5430 - Object-Oriented Analysis and Design
Customer
Catalogue
Librarian
Bookshelf
1.Member w/ Card and book
2. checks Card
3.request bok
4. book available
5. locate book
6. books location
7. fetch book
return book
8. checkout book
9. ack checkout
10. release book
11. returns book'
12. checkin book
13. ack checkin
14. return book to shelf
This is an Analysis-level Sequence Diagram. Note that it does not use real objects nor real methods.
Also, the Librarian’s activation bar is multi-part indicating that we may be using a difference Librarian.
1.2 More on Interaction Diagram Syntax

Procedure call – this is a blocking call of another procedure and uses a solid, filled in arrow
head
See #3 below.
© 2011 Mike Rowe
Page 4
2/8/2016 4:47:00 PM
Notes: 008 – Introduction to Interaction Diagrams
CS/SE3430 / CS5430 - Object-Oriented Analysis and Design

Message sent – rather than directly calling another procedure we can send it a message (kind
of like sending it a text message) the receiving process can process it when it gets around to it.
The arrow on Messages is open
See # 2 below.

Condition – some messages may be conditionally sent. The condition is contained within ‘[ ]’ .
See #6 below.

Iteration marker – (this notation is an extension of a condition) a message may be sent to each
of many objects in a collection.
o When these messages are prefaced by a ‘*’ for some unknown number. [ I := 1 . . 10] will
send 10 messages, [ x < 10 ] iterates while x is less than 10.
See #8 below.

Return – When a return from a message does not contain actual parameters or values, it is just
an ACK that the message was processed, we used a dashed return message line.
o Generally these are assumed (left out of the diagram) to de-clutter a diagram.
o Returns are important for synchronizations (when we need to wait for something to
complete, for instance wait for an elevator to stop at a floor before opening a door).
See #4 below.

Deletion – A deletion explicitly shows the end of the life of an object. An ‘X’ on its lifeline
indicates its destruction. See the ‘X’ in the figure below.

Asynchronous messages – Typical calls are synchronous function calls that block further
processing until the called message returns. But, with
o Asynchronous messages do NOT block the caller process while waiting for a return.
o Note: The book uses solid arrows to Synchronous calls and Rose uses open arrows or half
arrows for Asynchronous messages.
o An asynchronous message can:
 Create a new thread
 Create a new object
 Communicate with another thread
 Communicate with another full process – generally through some form of message
queue.
See # 5 below.
© 2011 Mike Rowe
Page 5
2/8/2016 4:47:00 PM
Notes: 008 – Introduction to Interaction Diagrams
CS/SE3430 / CS5430 - Object-Oriented Analysis and Design
ObjectA
ObjectC
ObjectB
1: ObjectB
2: message
2: messageName()
1. create instance
of ObjectB
3: functionCalled()
4. Return
3: Procedure call
4: what was returned
5: asychronousMessageName()
5. Asynchronous Call
6: [validLibCard] requestCheckOut()
6. Conditional
message
7:
8: [(I:= 1 .. 10) && x < 5]
sendMessage()
7. Intra object
message
8. Iteration
Deletion of
an object
Example: The Elevator System Scenario (Analysis-level Sequence Diagram):
1. User A presses Up Floor Button at Floor 3 to request Elevator. { user A wishes to go to Floor 7 }
2. Floor button sends a signal to the Elevator Controller
3. Elevator Controller send signal that turns on the UP Floor button
4. Elevator Controller sends a message that starts the elevator moving to the 3 rd Floor.
5. An Elevator arrives at Floor 3 and sends message to the Elevator Controller that it is at the 3 rd floor.
6. Elevator Controller sends a message to open the elevator door.
7. Elevator door opens
8. Elevator door sends a message to the Elevator controller that the door is open.
9. Elevator controller requests a 15 second interval from the timer
10. User A enters the elevator
11. User A pressed the 7th Floor button in the Elevator
12. The 7th Floor button sends a message to the Elevator controller requesting the 7 th floor.
13. The Elevator controller added the 7th floor to the stops requested list.
14. It contains User B who has entered the Elevator at Floor 1 and pressed the Elevator Button for
Floor 9.
15. Elevator controller turns off the Up Floor Button on floor 3
16. Timer sends a message to the Elevator Controller indicating a timeout.
17. Elevator controller sends a message to the door to close
18. The door sends a message to the Elevator controller indicating the door has closed.
19. The Elevator Controller sends a message to the Elevator to move to Floor 7.
20. The Elevator sends a message that it has arrived at Floor 7.
© 2011 Mike Rowe
Page 6
2/8/2016 4:47:00 PM
Notes: 008 – Introduction to Interaction Diagrams
CS/SE3430 / CS5430 - Object-Oriented Analysis and Design
21. Elevator Controller sends a message to open the elevator door.
22. Elevator door opens
23. Elevator door sends a message to the Elevator controller that the door is open.
24. Elevator controller requests a 15 second interval from the timer
25. User A leaves the elevator
26. The Elevator controller turns of the elevators 7th floor request button.
27. Timer sends a message to the Elevator Controller indicating a timeout.
28. Elevator controller sends a message to the door to close
29. Elevator proceeds to Floor 9 with User B.
Class Plans at this point:
 Do a sequence diagram for the above fast and in class on the board.
 Then discuss collaboration diagram
 Do the collaboration diagram for the above sequence diagram.
 Discuss the benefits of a collaboration diagram over a sequence diagram and sequence
diagrams over collaboration diagrams.
© 2011 Mike Rowe
Page 7
2/8/2016 4:47:00 PM
Notes: 008 – Introduction to Interaction Diagrams
CS/SE3430 / CS5430 - Object-Oriented Analysis and Design
User
UpBttn :
UpButton
7thFloorBttn :
7thFloorButton
ElCntrl
El : Elevator
Door : ElDoor
t0:Timer
1: pushBttn
2: requestFloor
3: turnOnLight
4: moveToFloor
5:
6: turnOffLight
7: openDoor
8: getOn
9: startTimer
10:
11: pushBttn
12: closeDoor
13: requestFloor
14: addFloor
15: turnOnLight
16: moveToFloor
17:
18: openDoor
19: startTimer
© 2011 Mike Rowe
Page 8
2/8/2016 4:47:00 PM
t1:Timer
Notes: 008 – Introduction to Interaction Diagrams
CS/SE3430 / CS5430 - Object-Oriented Analysis and Design
1.3 Collaboration Diagrams

Collaboration Diagrams are another kind of interaction diagram. It shows the ordered flow of messages
between objects but not time latencies.
 Collaboration diagrams contain Actors, Objects, Links, and Activations.
 Objects are shown as rectangles, starting off, they just have class_name labels, then to increase clarity, the
labels are refined to have object_name :: class_name labels.
 Links are non-directed arcs labeled with the association name.
 Activations are associated with each link and represent the direction and message(s) names that flow
between the two objects.
o An activation has a number representing its order in the sequence and a message name.
o Activations use the same symbols as sequence diagrams ti differentiate between messages, blocking
function calls and non-blocking calls.
 An object is said to be active as soon as it receives a message and non-active after it returns. The returns
are generally not shown.
 Each message has a sequence number representing its order.
 Benefit is that it allows the grouping of interacting objects in 2-space rather than in 1-space. This gives a
better picture of collaboration among objects.
 Also easy to identify common messages that each object should service/send.
Collaboration Diagrams contains message sequence information, but does not show the precise timing detail that
the Sequence Diagram does.
Rose allows one to switch views from Sequence to Collaboration Diagrams. See the “Go to Sequence or
Collaboration Diagram” option on the main menu bar Browse option.
© 2011 Mike Rowe
Page 9
2/8/2016 4:47:00 PM
Notes: 008 – Introduction to Interaction Diagrams
CS/SE3430 / CS5430 - Object-Oriented Analysis and Design
Collaboration Diagram of the same sequence
diagram used two figures above
7:
ObjectB
Link to self
3: functionCalled()
ObjectC
4: what was returned
5: asychronousMessageName()
8: [(I:= 1 .. 10) && x < 5]
6: [validLibCard] requestCheckOut()
2: messageName()
1: ObjectB
Object
Instance
Links
Object Link
ObjectA
© 2011 Mike Rowe
Page 10
2/8/2016 4:47:00 PM
Notes: 008 – Introduction to Interaction Diagrams
CS/SE3430 / CS5430 - Object-Oriented Analysis and Design
El Door
7: open
El 7th Floor Button
22.
.
12
11
21.
6. Open
28.
17. closeDoor
23.
8: doorOpen
7
ff
t_
es
qu
O
rn
tu
re
.
26
:p
re
ss
18. doorClosed
19. move_7
10. enter
25. leave
4. move_3
Elevator
Actor
13. add_7
El Cntl
5: at_3
20. at_7
24
9: timer(15)
16. timeOut
2:
re
qu
es
tU
p
3.
Up
tu
rn
O
n
15
.t
ur
nO
ff
ss
pre
1:
27.
El Up Button
Timer
1 Collaboration diagram of the Elevator Sequence Diagram.
1.3.1 What can we discover from the above collaboration diagram?







Message 4 (move_3) and 19 (move_7) should be combined into the same message, along with all of the
other possibilities moveToFloor( floorNum )
Message 5 (at_3) and 20 (at_7) should be generalized into at(floorNum)
Message 3 (turnOn) and 15 (turnOff) could be generalized to turn( state)
Message 26 (turnOff) indicates that we missed turning the button on
ElFloor7Button and ElUpButton support common operations, Inheritance is indicated from a Button Class
Messages 8 and 23 (doorOpen), 17 and 28 (closeDoor), 18 (doorClose), 6 and 21 (open):
o Are confusing
o Should be combined into a request(open | close) and a status(open | close)
Message 13 (add_7) should be generalized add(floorNum) – we know that floor 9 and 3 are discussed.
© 2011 Mike Rowe
Page 11
2/8/2016 4:47:00 PM
Notes: 008 – Introduction to Interaction Diagrams
CS/SE3430 / CS5430 - Object-Oriented Analysis and Design
7thFloorBttn :
7thFloorButton
11: pushBttn
1: pushBttn
User
UpBttn :
UpButton
15: turnOnLight
13: requestFloor
2: requestFloor
14: addFloor
3: turnOnLight
6: turnOffLight
8: getOn
5:
17:
El :
Elevator
ElCntrl
4: moveToFloor
16: moveToFloor
19: startTimer
10:
9: startTimer
7: openDoor
12: closeDoor
18: openDoor
Door :
ElDoor
t1:Timer
t0:Timer
Figure 2: Collaboration Diagram auto generated from Rose sequence diagram
© 2011 Mike Rowe
Page 12
2/8/2016 4:47:00 PM
Download