330 likes | 355 Views
Interaction and Communication Diagrams. Patrick Bailey Keith Vander Linden Calvin College. Interaction diagrams describe how groups of objects collaborate in some behavior. The UML defines several forms of interaction diagram, of which the most common is the sequence diagram.
E N D
Interaction and Communication Diagrams Patrick Bailey Keith Vander Linden Calvin College
Interaction diagrams describe how groups of objects collaborate in some behavior. The UML defines several forms of interaction diagram, of which the most common is the sequence diagram. Ref: Martin Fowler – UML Distilled, 3rd Edition
Sequence Diagrams You should use sequence diagrams when you want to look at how several objects interact with each other within a single use case. Sequence diagrams are good at showing collaborations among the objects; they are not so good at precise definition of the behavior. Ref: Martin Fowler – UML Distilled, 3rd Edition
Key Benefits Summarize • Analyze and design scenarios between objects. • Refine object definition and behavior. • Executable representation • Basis for test cases
What’s in a name… z:Dishwasher :Dishwasher x: { Lifeline An instance of the class Dishwasher which is named z. Unspecified classifier. An anonymous instance of the class Dishwasher. For the first two, Rhapsody looks for an existing class OR asks if you are creating a new one.
From Rhapsody’s Documentation The recipient of a message is either a class or a reactive class. Reactive classes have statecharts, whereas nonreactive classes do not. Reactive classes can receive events, triggered operations, and primitive operations.Non-reactive classes can receive only messages that are calls to primitive operations. Events are usually shown with slanted arrows to imply that they are asynchronous (delivery takes time). Triggered operations are shown with straight arrows to imply that they are synchronous (happen immediately).
Messages A message represents an interaction between objects, or between an object and the environment. A message can be an event, a triggered operation, or a primitive operation. In the metamodel, a message defines a specific kind of communication. The communication could be raising a signal, invoking an operation, or creating or destroying an instance.
Synchronous Message The UML standard uses a straight line with a solid arrow at the end to represent a synchronous message. The message is noted on the line along with the inputs to the message. startSystem(mode = 1)
Return Message Return messages are represented by a dash line with an open arrow at the end. Return values can be expressed if needed. status_result
Example of Centralized Control Execution Occurence Ref: Martin Fowler – UML Distilled, 3rd Edition
Example of Distributed Control Ref: Martin Fowler – UML Distilled, 3rd Edition
Creation and Deletion of Participants Ref: Martin Fowler – UML Distilled, 3rd Edition
Slanted Messages (Asynchronous) In the UML standard, messages with an open arrowhead are asynchronous. Rhapsody adds to the standard. A message drawn on a slant is interpreted as an event if the target is a reactive class, and as a primitive operation if the target is a nonreactive class. A slanted message emphasizes that time passes between the sending and receiving of the message. Slanted messages can cross each other.
Creating a Condition Mark Acondition mark (or state mark) is displayed on an instance line. A condition mark shows that the object has reached a certain condition or is in a certain state. Often, the name corresponds to a state name in the object's statechart.
Creating a Timeout • The notation for timeouts is similar to the notation for events sent by an object to itself. There are two differences: • A timeout starts with a small box. • The name is a tm(x). • The label on a timeout arrow is a parameter specifying the length of the timeout. Timeouts are always messages-to-self.
Creating a Canceled Timeout When designing a software system, you can establish waiting states, during which your program waits for something to occur. If the event occurs, the timeout is canceled. The sequence diagram shows this with a canceled timeout symbol. If it does not happen, the timeout wakes up the instance and resumes with some sort of error recovery process. Canceled timeouts are always messages-to-self.
Common Operators for Interaction Frame Ref: Martin Fowler – UML Distilled, 3rd Edition
Interaction Frames procedure dispatch foreach (lineitem) if (product.value > $10K) careful.dispatch else regular.dispatch end if end for if (needsConfirmation) messenger.confirm end procedure Ref: Martin Fowler – UML Distilled, 3rd Edition
Use of Reference Referenced frame
Frame Name Reference Example Continued
Rhapsody’s Implementation The Toolbar
Communication Diagrams These emphasize the organizations of objects that participate in an interaction. Typically, it is vertically oriented, and unlike sequence diagrams they do not show the lifeline of an object nor do they show the focus of control.
Example of Communication Diagram http://www.agilemodeling.com/artifacts/communicationDiagram.htm
Which comes first – collaboration or class diagrams? • Generally, make an initial pass on classes • Collaboration diagrams may require you to re-evaluate your class design. • It is a cyclic, iterative process of understanding.
Final thought • To model flows of control by timing order, the sequence diagram is more appropriate. • Communication diagrams are best when modeling flows of control by organization.