Interaction Diagram Sequence Diagram Collaboration Diagram Sequence Diagram

  • Slides: 25
Download presentation
Interaction Diagram Sequence Diagram & Collaboration Diagram

Interaction Diagram Sequence Diagram & Collaboration Diagram

Sequence Diagram • Describe how groups of objects collaborate in some behavior. Most common

Sequence Diagram • Describe how groups of objects collaborate in some behavior. Most common interaction diagram is the sequence diagram. • A sequence diagram captures the behavior of a single scenario. It describes the interaction among objects, arranged in a chronological order. • Sequence diagrams are particularly important to designers because they clarify the roles of objects in a flow and provide basic input for determining class responsibilities and interfaces. • Unlike a collaboration diagram, a sequence diagram includes chronological sequences (explicit sequence of messages), but does not include object relationships.

Two style in sequence diagram • Centralized control - one participant pretty much doing

Two style in sequence diagram • Centralized control - one participant pretty much doing all the processing and other participants there to supply data. • Distributed control - processing is split among many participants, each one doing a little bit of the algorithm. • When to use sequence diagram? – want to look at the behavior of several objects within a single use case. – Sequence diagrams are good at showing collaborations among the objects but not so good at precise definition of the behavior.

Centralized Vs Distributed control • Most people use centralized control because it's simpler &

Centralized Vs Distributed control • Most people use centralized control because it's simpler & all the processing is in one place. • Object bigots strongly prefer distributed control. • Main goals of good design is to localize the effects of change. Data and behavior often change together. So putting the data and the behavior together in one place is the first rule of object-oriented design. • So distributing control create more opportunities for using polymorphism rather than using conditional logic.

Consider a simple scenario. . . • We have an order and are going

Consider a simple scenario. . . • We have an order and are going to invoke a command on it to calculate its price. • To do that, the order needs to look at all the line items on the order and determine their prices, which are based on the pricing rules of the order line's products. • Having done that for all the line items, the order then needs to compute an overall discount, which is based on rules tied to the customer.

Cond. . . • Think of the participants as objects & their roles to

Cond. . . • Think of the participants as objects & their roles to draw sequence diagram. • Sequence diagrams show the interaction by showing each participant with a lifeline that runs vertically down the page and the ordering of messages by reading down the page. • Each lifeline has an activation bar that shows when the participant is active in the interaction. • The first message doesn't have a participant that sent it, as it comes from an undetermined source. It's called a found message.

Cond. . . • The sequence of messages get. Quantity, get. Product, get. Pricing.

Cond. . . • The sequence of messages get. Quantity, get. Product, get. Pricing. Details, and calculate. Base. Price needs to be done for each order line on the order, while calculate. Discounts is invoked just once. • A Participants as object syntax is name : Class, where both the name and the class are optional, but you must keep the colon if you use the class.

Cond. . . • Naming is useful to correlate participants on the diagram. The

Cond. . . • Naming is useful to correlate participants on the diagram. The call get. Product is shown returning a. Product, which is the same name, and therefore the same participant, as the a. Product that the get. Pricing. Details call is sent to. • Note a return arrow for only this call to show the correspondance.

Distributed control approach • The basic problem is still the same, but the way

Distributed control approach • The basic problem is still the same, but the way in which the participants collaborate to implement is different. • The Order asks each Order Line to calculate its own Price. The Order Line itself further hands off the calculation to the Product; note how we show the passing of a parameter. • Similarly, to calculate the discount, the Order invokes a method on the Customer. Because it needs information from the Order to do this, the Customer makes a reentrant call (get. Base. Value) to the Order to get the data.

Great strength of interaction diagrams • From these two diagrams - how clearly the

Great strength of interaction diagrams • From these two diagrams - how clearly the sequence diagram indicates the differences in the participants interaction. • They aren't good at showing details of algorithms, such as loops and conditional behavior. • They make the calls between participants crystal clear and give a really good picture about which participants are doing which processing. • The second thing - clear difference in styles between the two interactions.

Creating and Deleting Participants • draw the message arrow directly into the participant box

Creating and Deleting Participants • draw the message arrow directly into the participant box • A message name is optional but usually mark it with "new" in any case. • Participant immediately does something once it's created then start an activation right after the participant box. Eg: query command. • Deletion of a participant is indicated by big X. – A message arrow going into the X indicates one participant explicitly deleting another; – An X at the end of a lifeline shows a participant deleting itself.

Creation and deletion of participants

Creation and deletion of participants

Loops, Conditionals, and the Like • A common issue with sequence diagrams is how

Loops, Conditionals, and the Like • A common issue with sequence diagrams is how to show looping and conditional behavior? • Treat sequence diagrams as a visualization of how objects interact rather than as a way of modeling control logic. • Show control structures with an activity diagram or indeed with code itself. • Both loops and conditionals use interaction frames, which are ways of marking off a piece of a sequence diagram

procedure dispatch foreach (lineitem) if (product. value > $10 K) careful. dispatch else regular.

procedure dispatch foreach (lineitem) if (product. value > $10 K) careful. dispatch else regular. dispatch end if end for if (needs. Confirmation) messenger. confirm end procedure

 • Frames consist of some region of a sequence diagram that is divided

• Frames consist of some region of a sequence diagram that is divided into one or more fragments. • Each frame has an operator and each fragment may have a guard. Only the fragment whose guard is true will execute. • UML 1 used iteration markers and guards. An iteration marker is a * added to the message name. Add some text in square brackets to indicate the basis of the iteration. • Guards are a conditional expression placed in square brackets and indicate that the message is sent only if the guard is true. • Interaction frames are new in UML 2.

Older conventions for control logic

Older conventions for control logic

Synchronous and Asynchronous Calls • Caller sends a synchronous message, it must wait until

Synchronous and Asynchronous Calls • Caller sends a synchronous message, it must wait until the message is done, such as invoking a subroutine. • Caller sends an asynchronous message, it can continue processing and doesn't have to wait for a response. • Asynchronous calls used in multithreaded applications and in message-oriented middleware. It gives better responsiveness and reduces the temporal coupling but is harder to debug. • In UML 2, filled arrowheads-synchronous message, stick arrowheads-asynchronous message.

Other useful forms of interaction diagrams • Communication diagrams, for showing connections; and timing

Other useful forms of interaction diagrams • Communication diagrams, for showing connections; and timing diagrams, for showing timing constraints. • CRC (Class-Responsibility-Collaboration) diagrams- most valuable techniques with a good OO design to explore object interactions, because it focuses on behavior rather than data. CRC isn't part of the UML but very popular technique among skilled object designers.

Collaboration Diagram • A collaboration diagram describes a pattern of objects interaction; it shows

Collaboration Diagram • A collaboration diagram describes a pattern of objects interaction; it shows objects interaction by their links to each other and the messages sent to each other. • Unlike a sequence diagram, a collaboration diagram shows the relationships among the objects.

Contents of Collaboration Diagrams • A link is a relationship among objects across which

Contents of Collaboration Diagrams • A link is a relationship among objects across which messages can be sent (shown as a solid line between two objects). • An object interacts with, or navigates to, other objects through its links to them. • A link can be an instance of an association, or it can be anonymous, meaning that its association is unspecified.

Events’ flow of the use case “Receiver Deposit Item”

Events’ flow of the use case “Receiver Deposit Item”

 • In collaboration diagrams, a message is shown as a labeled arrow placed

• In collaboration diagrams, a message is shown as a labeled arrow placed near a link. This means that the link is used to transport, or otherwise implement the delivery of the message to the target object. • The arrow points along the link in the direction of the target object (the one that receives the message). • The arrow is labeled with the name of the message, and its parameters. The arrow may also be labeled with a sequence number to show the sequence of the message in the overall interaction. • A message can be unassigned, meaning that its name is a temporary string that describes the overall meaning of the message. You can later assign the message by specifying the operation of the message's destination object.