Forward Engineering from Interaction Diagrams - can it be - DiVA
10 Interaction Diagrams
-
Upload
madzani-nusa -
Category
Technology
-
view
1.720 -
download
0
description
Transcript of 10 Interaction Diagrams
![Page 1: 10 Interaction Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022051013/5481b52eb4af9fe25f8b45ea/html5/thumbnails/1.jpg)
TK2023 Object-Oriented Software Engineering
CHAPTER 10
INTERACTION DIAGRAMS
![Page 2: 10 Interaction Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022051013/5481b52eb4af9fe25f8b45ea/html5/thumbnails/2.jpg)
INTRODUCTION
UML provides interaction diagrams for illustrating how objects interact via messages.
Interaction diagrams are used for dynamic object modelling.
There are two common types: sequence diagram communication diagram
![Page 3: 10 Interaction Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022051013/5481b52eb4af9fe25f8b45ea/html5/thumbnails/3.jpg)
Sequence diagrams show interactions in a fence format.Example:
class AddressBookApp {private AddressBook addrBook;…public void addContact() {
addrBook.addNewContact();addrBook.reset();
}}…
AddressBookApp app = new AddressBookApp();…app.addContact();
: AddressBookApp : AddressBook
addContact()addNewContact
reset
![Page 4: 10 Interaction Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022051013/5481b52eb4af9fe25f8b45ea/html5/thumbnails/4.jpg)
Communication diagrams show interactions in a graph format.Example:
class AddressBookApp {private AddressBook addrBook;…public void addContact() {
addrBook.addNewContact();addrBook.reset();
}}…
AddressBookApp app;app = new AddressBookApp();…app.addContact();
: AddressBookApp
addrBook : AddressBook
addContact()
1: addNewContact
2: reset
![Page 5: 10 Interaction Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022051013/5481b52eb4af9fe25f8b45ea/html5/thumbnails/5.jpg)
SEQUENCE DIAGRAM VS COMMUNICATION DIAGRAMType Strengths Weaknesses
sequence Clearly shows sequence or time ordering of messages
Large set of detailed notation options
Forced to extend to the right when adding new objects; consumes horizontal space
communication Space economical - flexibility to add new objects in two dimensions
More difficult to see sequence of messages
Fewer notation options
![Page 6: 10 Interaction Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022051013/5481b52eb4af9fe25f8b45ea/html5/thumbnails/6.jpg)
LIFELINE BOXES
Informally, lifeline boxes represent the participants in an interaction.
:Sale
lifeline box representing an unnamed instance of class Sale
![Page 7: 10 Interaction Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022051013/5481b52eb4af9fe25f8b45ea/html5/thumbnails/7.jpg)
s1 : Sale lifeline box representing a named instance of class Sale
sales : ArrayList<Sale>
sales[ i ] : Sale
lifeline box representing an instance of an ArrayList class, parameterized to hold Sale objectslifeline box representing one instance of class Sale, selected from the sales collection.
![Page 8: 10 Interaction Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022051013/5481b52eb4af9fe25f8b45ea/html5/thumbnails/8.jpg)
BASIC MESSAGE EXPRESSION SYNTAX
: Register : Store
doA
message send
Syntax for message expressions:initialize(code)initialized = getProductDescription(id)d = getProductDescription(id:ItemID)d = getProductDescription(id:ItemID) : ProductDescription
![Page 9: 10 Interaction Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022051013/5481b52eb4af9fe25f8b45ea/html5/thumbnails/9.jpg)
BASIC SEQUENCE DIAGRAM NOTATION A (synchronous) message between objects is
represented with a message expression on a filled-arrowed solid line between the vertical lifelines. The time ordering is from top to bottom.
![Page 10: 10 Interaction Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022051013/5481b52eb4af9fe25f8b45ea/html5/thumbnails/10.jpg)
: Register : Sale
doA
doB
doX
doC
doD
typical sychronous message shown with a filled-arrow line
a found message whose sender will not be specified
execution specification bar indicates focus of control
![Page 11: 10 Interaction Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022051013/5481b52eb4af9fe25f8b45ea/html5/thumbnails/11.jpg)
There are two ways to show the return result from a message:
: Register : Sale
d1 = getDate
getDate
doX
aDate
![Page 12: 10 Interaction Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022051013/5481b52eb4af9fe25f8b45ea/html5/thumbnails/12.jpg)
A message being sent from an object to itself is shown using a nested activation bar.
: Register
doX
clear
![Page 13: 10 Interaction Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022051013/5481b52eb4af9fe25f8b45ea/html5/thumbnails/13.jpg)
Object creation notation is shown below:
: Register : Sale
makePayment(cashTendered)
: Paymentcreate(cashTendered)
authorize
note that newly created objects are placed at their creation "height"
![Page 14: 10 Interaction Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022051013/5481b52eb4af9fe25f8b45ea/html5/thumbnails/14.jpg)
The following is also permissable:
: Register : Sale
makePayment(cashTendered)
: PaymentPayment(cashTendered)
authorize
![Page 15: 10 Interaction Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022051013/5481b52eb4af9fe25f8b45ea/html5/thumbnails/15.jpg)
Looping constructs are supported in UML via frames. Frames have an operator and a guard.
a UML loop frame , with a boolean guard expression
enterItem(itemID, quantity)
: B
endSale
description , total
makeNewSale
[ more items ]loop
: A
![Page 16: 10 Interaction Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022051013/5481b52eb4af9fe25f8b45ea/html5/thumbnails/16.jpg)
Conditional constructs are represented as OPT frames.
calculate
: Bar
yy
xx
[ color = red ]opt
: Foo
![Page 17: 10 Interaction Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022051013/5481b52eb4af9fe25f8b45ea/html5/thumbnails/17.jpg)
Mutally exclusive conditional messages are represented as ALT frames.
: B: A
calculate
doX
: C
calculate
[ x < 10 ]alt
[ else ]
![Page 18: 10 Interaction Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022051013/5481b52eb4af9fe25f8b45ea/html5/thumbnails/18.jpg)
Representing iteration over a collection:
an action box may contain arbitrary language statements (in this case, incrementing ‘i’ )
it is placed over the lifeline to which it applies
st = getSubtotal
lineItems[i] :SalesLineItem
t = getTotal
[ i < lineItems.size ]loop
: Sale
i++
This lifeline box represents one instance from a collection of many SalesLineItem objects.
lineItems[i] is the expression to select one element from the collection of many SalesLineItems ; the ‘i” value refers to the same “i” in the guard in the LOOP frame
![Page 19: 10 Interaction Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022051013/5481b52eb4af9fe25f8b45ea/html5/thumbnails/19.jpg)
The following is simpler but excludes certain details:
st = getSubtotal
lineItems[i] :SalesLineItem
t = getTotal
loop
: Sale
![Page 20: 10 Interaction Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022051013/5481b52eb4af9fe25f8b45ea/html5/thumbnails/20.jpg)
Frames can be nested as shown below:
calculate
: Bar
xx
[ color = red ]opt
: Foo
loop(n)
![Page 21: 10 Interaction Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022051013/5481b52eb4af9fe25f8b45ea/html5/thumbnails/21.jpg)
An interaction diagram can contain references to other interaction diagrams. These references are called interaction occurrences.
![Page 22: 10 Interaction Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022051013/5481b52eb4af9fe25f8b45ea/html5/thumbnails/22.jpg)
interaction occurrence
note it covers a set of lifelines
note that the sd frame it relates to has the same lifelines: B and C
doA
: A : B : C
doB
sd AuthenticateUser
refAuthenticateUserauthenticate(id)
doX
doM1
: B : C
authenticate(id)
doM2
refDoFoo
sd DoFoo
doX
: B : C
doY
doZ
![Page 23: 10 Interaction Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022051013/5481b52eb4af9fe25f8b45ea/html5/thumbnails/23.jpg)
How to show polymorphism in a sequence diagram?
One approach is to use multiple sequence diagrams as shown in the following example.
![Page 24: 10 Interaction Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022051013/5481b52eb4af9fe25f8b45ea/html5/thumbnails/24.jpg)
:Register
authorize
doX
:Payment
:DebitPayment
doA
authorize
:Foo
doB
:CreditPayment
doX
authorize
:Bar
Payment
authorize() ...
CreditPayment
authorize()...
DebitPayment
authorize()...
![Page 25: 10 Interaction Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022051013/5481b52eb4af9fe25f8b45ea/html5/thumbnails/25.jpg)
BASIC COMMUNICATION DIAGRAM NOTATION A link is a connection path between two
objects; it indicates some form of navigation and visibility between the objects is possible.
More formally, a link is an instance of an association.
1: makePayment (cashTendered)2: foo
: Register :Sale
![Page 26: 10 Interaction Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022051013/5481b52eb4af9fe25f8b45ea/html5/thumbnails/26.jpg)
Each message between objects is represented with a message expression and a small arrow indicating the direction of the message.
A sequence number is added to show the sequential order of messages.
It is advisable not to number the starting message to simplify the overall numbering.
1: msg22: msg33: msg4
: Register :Sale
msg1
![Page 27: 10 Interaction Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022051013/5481b52eb4af9fe25f8b45ea/html5/thumbnails/27.jpg)
A message sent from an object to itself is shown below:
: Register
msg1
1: clear
![Page 28: 10 Interaction Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022051013/5481b52eb4af9fe25f8b45ea/html5/thumbnails/28.jpg)
Any message can be used to create an instance. The convention in the UML is to use a message named create.
If another message name is used, the message may annotated with the «create» stereotype.
1: create(cashier)
: Register :Sale
«create»1: Sale(cashier)
: Register :Sale
![Page 29: 10 Interaction Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022051013/5481b52eb4af9fe25f8b45ea/html5/thumbnails/29.jpg)
1: create(cashier)
: Register :Sale {new}
The UML tagged value {new} may optionally be added to the lifeline box to highlight the creation.
![Page 30: 10 Interaction Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022051013/5481b52eb4af9fe25f8b45ea/html5/thumbnails/30.jpg)
The order of messages is illustrated with sequence numbers. The first message is not numbered. The order and nesting of subsequent messages is
shown with a nested numbering scheme.
: Amsg1
: B1: msg2
: C
1.1: msg3
![Page 31: 10 Interaction Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022051013/5481b52eb4af9fe25f8b45ea/html5/thumbnails/31.jpg)
: Amsg1
: B1: msg2
: C
1.1: msg3
2.1: msg5
2: msg4
: D
2.2: msg6
![Page 32: 10 Interaction Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022051013/5481b52eb4af9fe25f8b45ea/html5/thumbnails/32.jpg)
: Amsg1
: B1: msg2
: C2: msg4
: D
: C
1.1: msg3
2.1: msg5
2.2: msg6
![Page 33: 10 Interaction Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022051013/5481b52eb4af9fe25f8b45ea/html5/thumbnails/33.jpg)
: A : B1: msg2
: C
1.1: msg3
: D
2.2: msg6
2.1: msg5
2: msg4
msg1
![Page 34: 10 Interaction Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022051013/5481b52eb4af9fe25f8b45ea/html5/thumbnails/34.jpg)
: A : : B1: msg2
: C
1.1: msg3
: D
2.2: msg6
2.1: msg5
2: msg4
msg1
![Page 35: 10 Interaction Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022051013/5481b52eb4af9fe25f8b45ea/html5/thumbnails/35.jpg)
: A : B
: C
2.1: msg5
2: msg4
: D
2.2: msg6
msg1 1: msg2
1.1: msg3
![Page 36: 10 Interaction Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022051013/5481b52eb4af9fe25f8b45ea/html5/thumbnails/36.jpg)
: A : B
: C
2.1: msg5
2: msg4
: D
2.2: msg6
msg1 1: msg2
1.1: msg3
![Page 37: 10 Interaction Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022051013/5481b52eb4af9fe25f8b45ea/html5/thumbnails/37.jpg)
: A : B
: C
2.1: msg5
2: msg4
: D
2.2: msg6
msg1 1: msg2
1.1: msg3
![Page 38: 10 Interaction Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022051013/5481b52eb4af9fe25f8b45ea/html5/thumbnails/38.jpg)
A conditional message is shown by following a sequence number with a conditional clause in square brackets. The message is sent only if the clause evaluates to true.
1 [ color = red ] : calculate: Foo : Bar
message1
![Page 39: 10 Interaction Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022051013/5481b52eb4af9fe25f8b45ea/html5/thumbnails/39.jpg)
The following diagram is an example with mutually exclusive conditional paths.
1a [color = red] : msg2
: A : B
: C
1a.1: msg3
msg1
: D
1b [not (color = red)] : msg4
1b.1: msg5
: E
2: msg6
![Page 40: 10 Interaction Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022051013/5481b52eb4af9fe25f8b45ea/html5/thumbnails/40.jpg)
Iteration notation is shown below.
If the details of the iteration clause are not important to the modeller, a simple * can be used.
1 * [ i = 1..n ]: num = nextInt: SimulatorrunSimulation : Random
1 * : num = nextInt: SimulatorrunSimulation : Random
![Page 41: 10 Interaction Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022051013/5481b52eb4af9fe25f8b45ea/html5/thumbnails/41.jpg)
The following shows how to represent iteration over a collection (such as an array or a Vector), sending the same message to each.
1 * [i = 1..n]: st = getSubtotal: Sale
t = getTotal lineItems[i]:SalesLineItem
1 *: st = getSubtotal: Sale
t = getTotal lineItems[i]:SalesLineItem
![Page 42: 10 Interaction Diagrams](https://reader033.fdocuments.in/reader033/viewer/2022051013/5481b52eb4af9fe25f8b45ea/html5/thumbnails/42.jpg)
As with sequence diagrams, multiple communication diagrams can be used to show each concrete polymorphic case.
:RegisterauthorizedoX
:Payment {abstract}
:DebitPayment :Foo
doAdoB
:CreditPayment :BardoX
authorize authorize