8. Object Interaction (8)

26
Object Interaction CSE 307 Presentation 11 CSE 307 Presentation 11 1

description

this is about object

Transcript of 8. Object Interaction (8)

Page 1: 8. Object Interaction (8)

Object Interaction

CSE 307 Presentation 11CSE 307 Presentation 11 11

Page 2: 8. Object Interaction (8)

Object MessagingObject Messaging

• Objects communicate by sending messagesObjects communicate by sending messages

• Sending the message getCost() to an Advert object might use the following syntaxobject, might use the following syntax

advertCost = anAdvert.getCost()

:Campaign anAdvert : AdvertgetCost( )

CSE 307 Presentation 11CSE 307 Presentation 11 22

Page 3: 8. Object Interaction (8)

Resilience of Designg

Resilient System

Application that caters

Resilient System

Real-world requirements

Application that caters for these requirements

Non Resilient

R l ldApplication that caters

Non- Resilient System

CSE 307 Presentation 11CSE 307 Presentation 11 33

Real-world requirements

for these requirements

Page 4: 8. Object Interaction (8)

Sequence DiagramsSequence Diagrams

• Show an interaction between objectsShow an interaction between objects arranged in a time sequence

• Can be drawn at different levels of detail and• Can be drawn at different levels of detail and to meet different purposes at several stages in the development life cyclethe development life cycle

• Typically used to represent the detailed object i i h f finteraction that occurs for one use case or for one operation

CSE 307 Presentation 11CSE 307 Presentation 11 44

Page 5: 8. Object Interaction (8)

Sequence DiagramsSequence Diagrams

• Vertical dimension shows timeVertical dimension shows time• Objects involved in interaction appear horizontally across the page and representedhorizontally across the page and represented by lifelines

• Messages are shown by a solid horizontalMessages are shown by a solid horizontal arrow

• The execution of an operation is shown by anThe execution of an operation is shown by an activation

CSE 307 Presentation 11CSE 307 Presentation 11 55

Page 6: 8. Object Interaction (8)

Sequence diagramSequence diagram

:Client :Campaign :Advert

Campaign Manager

p ggetName()

listCampaigns() *getCampaignDetails()

listAdverts() *getAdvertDetails()

Advert() newAd:AdvertaddNewAdvert()

Activation

CSE 307 Presentation 11CSE 307 Presentation 11 66

Object lifeline Object creation

Page 7: 8. Object Interaction (8)

Boundary & Control ClassesBoundary & Control Classes

• Most use cases imply at least one boundaryMost use cases imply at least one boundary object that manages the dialogue between the actor and the system – in the nextthe actor and the system  in the next sequence diagram it is :AddAdvertUI

• The control object is :AddAdvert and this• The control object is :AddAdvert and this manages the overall object communication. 

CSE 307 Presentation 11CSE 307 Presentation 11 77

Page 8: 8. Object Interaction (8)

Boundary & Control ClassesUse Case: Add a new advert to a campaign

:AddAdvert :Client :Campaign :Advert Campaign Manager

p g

:AddAdvertUI

showClientCampaigns()selectClient()

startInterface()*getClient()

g

listCampaigns() *getCampaignDetails()

selectCampaign()showCampaignAdverts()listAdverts() *getAdvertDetails()listAdverts()

createNewAdvert()ddN Ad t()

Advert()addNewAdvert()addNewAdvert()

newAd:Advert

CSE 307 Presentation 11CSE 307 Presentation 11 88

Page 9: 8. Object Interaction (8)

Object DestructionObject Destruction

:Campaign :Advert

listAdverts()

:Campaign :Advert

*getAdvertDetails()

deleteAdvert()destroy()

X

Object destruction

CSE 307 Presentation 11CSE 307 Presentation 11 99

Page 10: 8. Object Interaction (8)

Reflexive MessagesReflexive Messages

:Client :Campaign :Advert

Campaign Manager

p ggetName()

listCampaigns() *getCampaignDetails()

checkCampaignBudget()

Details()

*getCost()

getOverheads()g ()

CSE 307 Presentation 11CSE 307 Presentation 11 1010

Page 11: 8. Object Interaction (8)

Focus of ControlFocus of Control

• Indicates times during an activation when processing is taking g p g gplace within that object

• Parts of an activation that are not within the focus of control t i d h f l ti i itirepresent periods when, for example, an operation is waiting 

for a return from another object

• May be shown by shading those parts of the activation y y g prectangle that correspond to active processing by an operation

CSE 307 Presentation 11CSE 307 Presentation 11 1111

Page 12: 8. Object Interaction (8)

Focus of ControlFocus of ControlCampaign Manager

:Client :Campaign :AdvertgetName()

Manager

listCampaigns()

checkCampaignB dget()

*getCampaignDetails()

checkCampaignBudget() * getCost()

tO h d ()getOverheads()

CSE 307 Presentation 11CSE 307 Presentation 11 1212

Page 13: 8. Object Interaction (8)

ReturnReturn

• A return is a return of control to the objectA return is a return of control to the object that originated the message that began the activationactivation

• Returns are shown with a dashed arrow, but it is optional to show them at all since it can beis optional to show them at all since it can be assumed that control is returned to the originating object at the end of the activationoriginating object at the end of the activation

CSE 307 Presentation 11CSE 307 Presentation 11 1313

Page 14: 8. Object Interaction (8)

Message TypesMessage Types

• A synchronous message or procedural call, shown with a full y g p ,arrowhead, causes the invoking operation to suspend execution until the focus of control has been returned to it

A h d ith h d• An asynchronous message, drawn with an open arrowhead, does not cause the invoking operation to halt execution while it awaits a return 

CSE 307 Presentation 11CSE 307 Presentation 11 1414

Page 15: 8. Object Interaction (8)

Further Notation:ClassA Cl B:ClassA :ClassB

a

Synchronous (blocking) message

A ti a

b

Asynchronous message

Construction marks to

An active object

b{b.sendtime –a.sendtime < 3 sec}

c< 5 sec.

{d receivetime

Construction marks to show time constrained

interval

d{d.receivetime –d.sendtime < 1.5 sec}

{e.sendtime -d i i

Callback

Here e is used as

e

d.receivetime < 6 sec}

Time {e’ – e < 6 sec}

Here e is used as shorthand for e.sendtime ande’ represents e.receivetime

CSE 307 Presentation 11CSE 307 Presentation 11 1515

constraints e.receivetime

Page 16: 8. Object Interaction (8)

Message BranchingMessage Branching:Campaign

checkCampaignBudget()Campaign Manager

budget:=checkCampaignBudget()checkCampaignBudget() results in further interaction

addCostedAdvert()

newAd:Adve[totalCost ≤ budget] Advert()

[totalCost > budget] Request()

rt

newRequest:Request[totalCost > budget] Request() st

CSE 307 Presentation 11CSE 307 Presentation 11 1616

Page 17: 8. Object Interaction (8)

Handling Complexity• Complex diagrams can be split into two or more smaller diagrams suitably annotated

• Alternatively a group of objects can be represented by a single lifeline, and interaction p y g ,among these objects is shown on a different diagramg

CSE 307 Presentation 11CSE 307 Presentation 11 1717

Page 18: 8. Object Interaction (8)

Handling Complexity

:AddAdvertUI

:AddAdvert

These flows are*getClient()

Campaign Manager

showClientCampaigns()selectClient()listCampaigns()

These flows are continued next figure

startInterface()*getClient()

selectCampaign() showCampaignAdverts()

listCampaigns()

listAdverts()

createNewAdvert()

listAdverts()

addNewAdvert() addNewAdvert()

CSE 307 Presentation 11CSE 307 Presentation 11 1818

Page 19: 8. Object Interaction (8)

Handling ComplexityCli t C i :Advert:Client :Campaign :Advert

*getClient()

listCampaigns() *getCampaignDetails()These flows are

listAdverts() *getAdvertDetails()

These flows are continued

from the previous figure

addNewAdvert()addNewAdvert()Advert() newAd:Advert

CSE 307 Presentation 11CSE 307 Presentation 11 1919

Page 20: 8. Object Interaction (8)

Object Grouping

Lifeline representing a set of objectstN ()

CampaignAdverts

:ClientCampaign Manager

set of objectsgetName()

listCampaigns()

checkCampaignBudget()

listCampaigns()

CSE 307 Presentation 11CSE 307 Presentation 11 2020

Page 21: 8. Object Interaction (8)

Collaboration DiagramsCollaboration Diagrams

• Hold the same information as sequence diagrams• Show links between objects that participate in the 

collaboration• No time dimension sequence is captured with sequence• No time dimension, sequence is captured with sequence 

numbers• Sequence numbers are written in a nested style (for example, 

3 1 d 3 1 1) t i di t th ti f t l ithi th3.1 and 3.1.1) to indicate the nesting of control within the interaction that is being modelled

CSE 307 Presentation 11CSE 307 Presentation 11 2121

Page 22: 8. Object Interaction (8)

Collaboration DiagramsOne allocation of responsibilities for use caseOne allocation of responsibilities for use caseAdd a new advert to a campaign

3.1: showClientCampaigns()3: selectClient()

4: selectCampaign() 4.1: showCampaignAdverts()

5: createNewAdvert() 5.1: addNewAdvert()

5.1.1: addNewAdvert()

:AddAdvertUI :AddAdvert newAd:Advert

2: startInterface()Campaign

3.1.1: listCampaigns()5.1.1.1: Advert()

4.1.1: listAdverts()2: startInterface()

1:*getClient()

p gManager

p g ()

3.1.1.1: *getCampaignDetails()

4.1.1.1: *getAdvertDetails()

:Client :Campaign :Advert

CSE 307 Presentation 11CSE 307 Presentation 11 2222

Page 23: 8. Object Interaction (8)

Message LabelsType ExampleType Example

• Simple message. 4: addNewAdvert()

•Nested call with return value.–The return value is placed in the variable name.

3.1.2: name:= getName()

•Conditional message.–This message is only sent if the

diti [b l > 0] i t

[balance > 0] 5: debit(amount)

condition [balance > 0] is true.

•Synchronization with other threads.

3.1a, 3. 1b / 4:playVideo()

–Message 4: playVideo() is invoked only once the two concurrent messages 3.1a and g3.1b are completed.

CSE 307 Presentation 11CSE 307 Presentation 11 2323

Page 24: 8. Object Interaction (8)

Navigating Links

checkCampaignBudget()2 tO h d

:Campaign:Client2: getOverheads

1: *getCost ()1: getCost ()

The direction in which a

:Advert

link can be navigated

CSE 307 Presentation 11CSE 307 Presentation 11 2424

Page 25: 8. Object Interaction (8)

Model Consistency• The allocation of operations to objects must be consistent with the class diagram and the 

i t t t h th t f thmessage signature must match that of the operation

• Every sending object must have the object f f th d ti ti bj treference for the destination object

– Either an association exists between the classes or another object passes the reference to the sender

– Message pathways should be carefully analysed

CSE 307 Presentation 11CSE 307 Presentation 11 2525

Page 26: 8. Object Interaction (8)

Model ConsistencyModel Consistency

• If both sequence and collaboration diagrams are prepared q g p pthey should be consistent

• Messages on interaction diagrams must be consistent with th t t h t f th ti i ti bj tthe statecharts for the participating objects

• Implicit state changes in interaction diagrams must be consistent with those explicitly modelled in statechartsp y

CSE 307 Presentation 11CSE 307 Presentation 11 2626