Download presentation
Presentation is loading. Please wait.
1
Systems Analysis and Design I
Session 6 Object Interaction
2
Recap Further discussion of class diagrams (Section 7.5.2, pp 198 – 201) Stereotypes: entity, boundary, control; association class Software and Specification Reuse Section 20.2 (pp. 585 – 586) Section 8.2 (pp. 234 – 237) Section 8.4 (pp. 246 – 247) Section – (pp. 252 – 253) Adding Further Structure (to Class Diagrams) Section – (pp. 237 – 244) Section (pp. 409 – 410) In this lecture you will learn … 2 2
3
Today Object Interaction and Collaboration CRC Cards
Section 9.2 (pp. 260 – 262) CRC Cards Section 7.6 (pp. 215 – 218) Communication Diagrams Section 7.4 (pp. 194 – 197) Section 9.4 (pp. 280 – 284) Sequence Diagrams Section 9.3 – (pp. 262 – 276) Model Consistency Section 9.7 (p. 289) In this lecture you will learn … 3 3
4
Object Interaction & Collaboration
How do you communicate, interact, and collaborate? Message Passing Objects communicate by sending messages This is a metaphor! When an object sends a message to another object, an operation is invoked in the receiving object The Campaign object sends a message to each of its Advert object currentAdvertCost = anAdvert.getCost() The aim of modelling object interaction is to determine the most appropriate scheme of message passing between objects to support a particular user requirement 4 4
5
Object Interaction & Collaboration
Appropriate distribution of object responsibility improves software modularity Each class tends not to be unduly complex, and as a result is easier to develop, to test and to maintain. Each class is relatively small and self-contained, and as a result has a much greater potential for reuse. The system is more resilient to changes in its requirements (see next slide) A modular system is easier to be maintained and upgraded to achieve high reliability to be implemented in small, manageable increments 5 5
6
Real-world requirements Application that caters for these requirements
Equivalent areas of change—a highly resilient system. A small change in requirements causes a much greater change in software—not a resilient system. 6 6
7
CRC Cards Class–Responsibility–Collaboration (CRC) cards
An effective technique for exploring the possible ways of allocating responsibilities to classes and the collaborations that are necessary to fulfil the responsibilities Brainstorm the classes Allocate each class to a team members For each use case, role play the interaction to distribute responsibilities among classes: each object identifies the object that he/she thinks is most appropriate to take on a needed responsibility for collaboration each object should be as lazy as possible, refusing to take on any responsibility unless persuaded by its fellow objects 7 7
8
Format of CRC Cards Class Name: Collaborations Responsibilities
Responsibilities of the class are listed in this section. Collaborations with other classes are listed here, together with a brief description of the purpose of the collaboration. 8 8
9
CRC Cards: Use Case Example
Use Case: Add a new advert to a campaign A campaign can consist of many adverts. Details of each advert are entered into the system with a target completion date and estimated cost. Glossary: Campaign: Adverts are organised into campaigns in order to achieve a particular objective.... Client: A company or organisation that wishes to obtain the services to develop and manage an advertising campaign, and design and produce adverts for the campaign
10
Advert provides advert details. Advert constructs new object.
Class Name Client Responsibilities Collaborations Provide client information. Campaign provides campaign details. Provide list of campaigns. Class Name Campaign Responsibilities Collaborations Provide campaign information. Provide list of adverts. Add a new advert. Advert provides advert details. Advert constructs new object. Class Name Advert Responsibilities Collaborations Provide advert details. Construct adverts. 10 10
11
Dynamic Analysis with UML
Sequence Diagrams Communication Diagrams Interaction Overview Diagrams Timing Diagrams In UML 1.x, communication diagrams are called collaboration diagrams interaction overview diagrams and timing diagrams do not exist 11 11
12
Sequence Diagrams A sequence diagram shows an interaction between objects arranged in a time sequence. Sequence diagrams can be drawn at different levels of detail and to meet different purposes at several stages in the development life cycle. Sequence diagrams are typically used to represent the detailed object interaction that occurs for one use case or for one operation. 12 12
13
Sequence diagram Frame label Sequence diagram is enclosed in a frame
:Client :Campaign :Advert getName listCampaigns listAdverts Advert newAd:Advert addNewAdvert Lifeline Activation or Execution Object creation :CampaignManager sd Add a new advert to a campaign loop Interaction Operator Interaction Constraint Combined Fragment (loop) [For all client’s campaigns] getCampaignDetails [For all campaign’s adverts] getAdvertDetails Frame label Sequence diagram is enclosed in a frame “sd” is used to determine the interaction diagram; interaction
14
Sequence Diagrams: Basic elements
Objects (or subsystems, components or other connectable elements) involved in interaction appear horizontally across the page Vertical dimension represents time Each object is represented by a lifeline. Once a message is received, the operation that has been invoked begins to execute The period of time during which an operation executes is called the execution occurrence or activation of an operation shown by a rectangle on the relevant lifeline. Messages are usually shown by a solid horizontal arrow A synchronous message or procedural call is shown with a full arrowhead, causes the invoking operation to suspend execution until the focus of control has been returned to it. It is optional to show reply messages (with dashed arrows) Why? Assume that control is returned to the originating object at the end of the activation in a destination object (except for asynchronous messages). 14 14
15
Sequence Diagrams: Example
Figure 9.4 on p. 265 :LifelineA :LifelineB Synchronous (blocking) message sd Interaction Name msg a Send message Event Occurrence (msg.sendEvent) Receive messaged Event Occurrence (msg.recieveEvent) start of Execution Occurrence end of Active State on lifeline showing pre-condition Message reply showing return of control 16 16
16
Boundary & Control Classes
Most use cases imply at least one boundary object that manages the dialogue between the actor and the system The control object is represented by the lifeline :AddAdvert and this manages the overall object communication.
17
Control lifeline Boundary lifeline :Client :Campaign :Advert
listCampaigns listAdverts Advert newAd:Advert :CampaignManager sd Add a new advert to a campaign loop :AddAdvertUI :AddAdvert addNewAdvert getClient selectClient selectCampaign getCampaignDetails startInterface [For all clients] showClientCampaigns showCampaignAdverts createNewAdvert [For all client’s campaigns] [For all campaign’s adverts] getAdvertDetails Boundary lifeline
18
Sequence Diagrams: Reflexive Message
:Client :Campaign :Advert getName listCampaigns checkCampaignBudget getCampaignDetails getCost :CampaignManager sd Check campaign budget loop getOverheads [For all client’s campaigns] [For all campaign’s adverts] Reflexive message A reflexive message that an object sends to itself is shown by a message arrow that starts and finishes at the same object lifeline. Figure 9.7 on p. 268 An object can send a message to itself. 19 19
19
Sequence Diagrams: Flow Control
Sequencing is shown by arranging messages vertically in the order of their occurrences Recall: the vertical dimension represents time. Selection (branching) is shown by a combined fragment rectangle with the interaction operator ‘alt’ (a short form of alternatives) The alt combined fragment has two (or more) compartments known as operands. Each operand corresponds to one of the alternatives in the combined fragment and should have an interaction constraint to indicate under what conditions it executes. Iteration (looping) is shown by a combined fragment rectangle with the interaction operator ‘loop’ The interaction in the loop combined fragment repeats as long as the guard condition in the interaction constraint evaluates as true. 22 22
20
Figure 9.16 on p. 275 alt interaction operator shows branching
:Client :Campaign :Advert getName listCampaigns ref :CampaignManager Advert addCostedAdvert newAd:Advert newRequest:Request alt [else] sd Add a new advert to a campaign if within budget List client campaigns [totalCost <= budget] Request Get campaign budget alt interaction operator shows branching Two interaction operands, one for each alternative Figure on p. 275 23 23
21
Figure 9.3 on p. 263 Frame label 24 Lifeline Activation or Execution
:Client :Campaign :Advert getName listCampaigns listAdverts Advert newAd:Advert addNewAdvert Lifeline Activation or Execution Object creation :CampaignManager sd Add a new advert to a campaign loop Interaction Operator Interaction Constraint Combined Fragment (loop) [For all client’s campaigns] getCampaignDetails [For all campaign’s adverts] getAdvertDetails A sequence diagram is enclosed in a frame Frame label 24 24
22
25
23
Sequence Diagrams: Object Creation and Destruction
Figure 9.6 on p. 267 listAdverts deleteAdvert Object destruction :Campaign :Advert delete getAdvertDetails X loop sd Delete advert Object creation is shown with the construction message (dashed arrow) going to the object symbol. Object destruction is indicated by a large X on the lifeline on the destruction point. 26 26
24
Sequence Diagrams: Handling Complexity
Complexity interactions can be modelled using various different techniques Interaction fragments Lifelines for subsystems or groups of objects Continuations Interaction Overview Diagrams Interaction occurrences and 27 27
25
Interaction fragments: Example
:Client :Campaign :Advert getName listCampaigns :CampaignManager sd Check campaign budget ref Gate showing the message enter this interaction occurrence List client campaigns Get campaign budget ref interaction operator indicates interaction occurrence that references an interaction fragment :Client :Campaign listCampaigns getCampaignDetails sd List client campaigns loop Gate showing the message enter this Interaction Fragment [For all client’s campaigns] Interaction fragment that is referenced in the “Check campaign budget” sequence diagram 28 28
26
Interaction Fragment example (cont’d)
Interaction fragment that is also referenced in Check campaign budget sequence diagram :Campaign :Advert getCost sd Get campaign budget loop getOverheads checkCampaignBudget :CampaignManager [For all campaign’s adverts]
27
Lifelines for subsystems or groups of objects
:Client :Campaign :Advert listCampaigns listAdverts Advert newAd:Advert :CampaignManager sd Add a new advert to a campaign loop :AddAdvertUI :AddAdvert addNewAdvert getClient selectClient selectCampaign getCampaignDetails startInterface [For all clients] showClientCampaigns showCampaignAdverts createNewAdvert [For all client’s campaigns] [For all campaign’s adverts] getAdvertDetails Boundary lifeline Control lifeline Lifelines for subsystems or groups of objects Complex interactions can also be split up using lifelines to represent groups objects and their interactions or to present subsystems.
28
Lifelines for subsystems or groups of objects
:ClientCampaigns ref ClientCampaignAds listCampaigns listAdverts :CampaignManager sd Add a new advert to a campaign :AddAdvertUI :AddAdvert addNewAdvert getClient selectClient loop selectCampaign [For all clients] showClientCampaigns startInterface showCampaignAdverts createNewAdvert Lifelines for subsystems or groups of objects Lifeline representing the interaction between a group of objects Complex interactions can also be split up using lifelines to represent groups objects and their interactions or to present subsystems. Complex interactions can also be split up using lifelines to represent groups objects and their interactions or to present subsystems.
29
Sequence diagram referenced in the
:Client :Campaign :Advert listCampaigns listAdverts Advert newAd:Advert sd ClientCampaignAds loop addNewAdvert getClient [For all client’s campaigns] getCampaignDetails [For all campaign’s adverts] getAdvertDetails Sequence diagram referenced in the Add a new advert to a campaign sequence diagram
30
Using Continuations NB: Dashed arrows are NOT part of UML!
getCost Within budget Budget spent :LifelineA :LifelineB :LifelineC alt sd Calculate costs [else] ref Identify under spend [Within budget] sd Authorise expenditure authorize stopExpenditure Calculate costs NB: Dashed arrows are NOT part of UML! Continuations are used to link sequence diagrams
31
Communication Diagrams
Communication diagrams hold the same information as sequence diagrams Can be drawn at various levels of detail and during different stages in the system development process Communication diagrams show links between objects that participate in the collaboration offer a view of object interactions that is easy to relate to the underlying collaborations because of visibility of links between objects (lifelines) No time dimension, sequence order is captured with sequence numbers Not suitable for complex interactions 34 34
32
Communication Diagrams: Notation
Message order is captured with sequence numbers, which are written in a nested style to indicate the nesting of control within the interaction that is being modelled: e.g., message occurs after message 3.1.1, and both are contained with the activation of message 3.1 :Campaign anAdvert:Advert getCost currentAdvertCost = anAdvert.getCost() 35 35
33
Control lifeline Boundary lifeline :Client :Campaign :Advert
listCampaigns listAdverts Advert newAd:Advert :CampaignManager sd Add a new advert to a campaign loop :AddAdvertUI :AddAdvert addNewAdvert getClient selectClient selectCampaign getCampaignDetails startInterface [For all clients] showClientCampaigns showCampaignAdverts createNewAdvert [For all client’s campaigns] [For all campaign’s adverts] getAdvertDetails Boundary lifeline
34
Communication Diagrams: Example
Figure 9.21 on p. 282 : Advert 4.1.2 *[For all campaign’s adverts]: getAdvertDetails 5.1.1: addNewAdvert :AddAdvertUI :AddAdvert :Client :Campaign :Advert 3.1: showClientCampaigns 3: selectClient 4: selectCampaign 4.1: showCampaignAdverts 4.1.1: listAdverts 5: createNewAdvert 5.1: addNewAdvert newAd:Advert 2: startInterface 3.1.1: listCampaigns 1 *[For all clients]: getClient :CampaignManager sd Add a new advert to a campaign 3.1.2 *[For all client’s campaigns]: getCampaignDetails 37 37
35
Communication Diagrams: Message Labels
Type of message Syntax 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 condition [balance > 0] is true. 5 [balance > 0]: debit(amount) Iteration 4.1 *[For all adverts]: getCost 38 38
36
sd Check campaign budget
:Client :Campaign :Advert getName listCampaigns checkCampaignBudget getCampaignDetails getCost :CampaignManager sd Check campaign budget loop getOverheads [For all client’s campaigns] [For all campaign’s adverts] :Campaign :Advert checkCampaignBudget 1*[For all adverts]: getCost 2: getOverheads The direction in which a link can be navigated may be shown if required. sd checkCampaignBudget
37
Model Consistency The communication/sequence diagrams should be mutually consistent with the class diagrams The allocation of operations to objects must be consistent with the class diagram and the message signature must match that of the operation Can be enforced through CASE tools Every sending object must have the object reference 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. This issue is key in determining association design 40 40
38
Take Home Messages Object Interaction and Collaboration CRC Cards
Communication Diagrams Sequence Diagrams Model Consistency In this lecture you have learned about … 41 41
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.