Behavioral System Sequence Diagrams Collaboration Diagrams Chapter 7

Behavioral System Sequence Diagrams: Collaboration Diagrams Chapter 7 Princess Nourah bint Abdulrahman University College of Computer and Information Sciences Department of Computer Science Dr. Doaa Sami Khafaga

Objective s ● Describe the evolutionary approach for using sequence diagrams to complete class diagrams ● Introduce the syntax of sequence diagrams ● Explain how message are interleaved between objects to build sequence diagrams S. H 2009 Software Engineering Behavioral Diagrams

Object behaviour modelling Interaction diagrams model how groups of object collaborate to perform some behavior Typically captures the behavior of a single use case S. H 2009 Software Engineering Behavioral Diagrams

System Sequence Diagrams S. H 2009 Software Engineering Behavioral Diagrams

System Sequence Diagrams ● A system sequence diagram illustrates events from actors to systems and the external response of the system. ● This activity occurs during the analysis phase of a development cycle; dependent on the creation of the use cases and identification of concepts. ● One diagram depicts one scenario. This is the main success scenario. ● Frequent or complex alternate scenarios could also be illustrated. ● A system is treated as a black box. S. H 2009 ● SSD is often accompanied by a textual description of the scenario Software Engineering to the left of the diagram. Behavioral Diagrams

System sequence Diagrams S. H 2009 Software Engineering Behavioral Diagrams

System Sequence Diagram (SSD) for a Use Case (UC) S. H 2009 Software Engineering Behavioral Diagrams

Message type in a sequence diagram ● Simple: This is a transfer of control from one object to another. ● Synchronous: If an object sends a synchronous message, it waits for an answer to that message before it proceeds with its business. ● Asynchronous: If an object sends an S. H 2009 asynchronous message, it doesn't wait for an answer before it proceeds. Software Engineering Behavioral Diagrams

Sequence Diagrams (SD) S. H 2009 Software Engineering Behavioral Diagrams

Sequence Diagrams (SD) S. H 2009 Software Engineering Behavioral Diagrams

Sequence Diagram Syntax S. H 2009 Software Engineering Behavioral Diagrams

Example of Sequence Diagram S. H 2009 Software Engineering Behavioral Diagrams

SSD for Process Sale scenario S. H 2009 Software Engineering Behavioral Diagrams

From Use Case to Sequence System Diagram How to construct an SSD from a use case: S. H 2009 1. Draw System as black box on right side 2. For each actor that directly operates on the System, draw a stick figure and a lifeline. 3. For each System events that each actor generates in use case, draw a message. 4. Optionally, include use case text to left of diagram. Software Engineering Behavioral Diagrams

Example: use cases to SSD S. H 2009 Software Engineering Behavioral Diagrams

Request Appointment SD S. H 2009 Software Engineering Behavioral Diagrams

Collaboration Diagrams ● Semantically equivalent to sequence diagrams. Objects are shown as icons, and can be placed anywhere on the page/screen. ● Sequence of message firings is shown by numbering the messages. ● S. H 2009 ● Easier to depict object links and layout with collaboration diagrams; they’re also more compact. ● Easier to see sequence with sequence diagrams. Software Engineering Behavioral Diagrams

Collaboration Diagrams S. H 2009 Software Engineering Behavioral Diagrams

Collaboration Diagrams A collaboration diagram describes a pattern of interaction among objects. Client Object It shows objects participating in the interaction by their links to each other and the messages that they send to each other. Link Supplier Object : Client An object is represented in three ways: Objectname: Classname, Objectname, and : Classname 1: Perform. Responsibility Message A link is a relationship among objects across which messages can be sent. In a collaboration diagram, a link is shown as a solid line between two objects. A link can be an instance of an association, or it can be anonymous – meaning that its association is unspecified. S. H 2009 Software Engineering Behavioral Diagrams : Supplier

Collaboration Diagrams ● A message is a communication between objects that conveys information with the expectation that activity will ensue. ● 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. S. H 2009 Software Engineering Behavioral Diagrams

Collaboration Diagrams ● The arrow may also be labeled with a sequence number to show the sequence of the message in the overall interaction. ● Sequence numbers are often used in collaboration diagrams, because they are the only way of describing the relative sequencing of messages. ● (A message can be unassigned, meaning that its name is a temporary string that describes the overall meaning of the message, like //get_schedule(). You can later assign the message by specifying the operation of the message's destination object. ● The specified operation will then replace the name of the message. ● Frequently locked in upon further analysis S. H 2009 Software Engineering Behavioral Diagrams

collaboration diagram notation S. H 2009 Software Engineering Behavioral Diagrams

Example: Collaboration Diagrams S. H 2009 Software Engineering Behavioral Diagrams

Example: Collaboration Diagrams This example shows the collaboration of objects to support the Request Appointment use case: Create a Schedule subflow. It is the “collaboration diagram equivalent” of the sequence diagram shown earlier. S. H 2009 Software Engineering Behavioral Diagrams

Collaboration Diagrams Vs Sequence Diagrams Same information expressed in different ways… ● Collaboration Diagrams ● Sequence Diagrams ● Show relationships in addition to interactions ● Better for visualizing patterns of collaboration ● Better for visualizing all of the effects on a given object ● Easier to use for brainstorming sessions S. H 2009 Software Engineering ● Show the explicit sequence of messages ● Better for visualizing overall flow ● Better for real-time specifications and for complex scenarios Behavioral Diagrams

Collaboration Diagrams Vs Object Diagrams ● A collaboration diagram without messages is also known as an object diagram. ● The relationships between objects are called links. ● An object diagram must be a valid instantiation of a static class diagram. ● Objects must have classes. ● Links between objects must be instances of associations between classes. ● Use this as a quick consistency check. S. H 2009 Software Engineering Behavioral Diagrams

Statecharts ● Class diagrams describes static structure of a system. ● Interaction diagrams describe the behaviour of a collaboration. ● How about describing the behaviour of a single object when it reacts to messages? ● Statecharts describe all possible states that an object can get in to, and how the object responds Software Engineering Behavioral Diagrams to events. ● S. H 2009 Statecharts

S. H 2009 Software Engineering Behavioral Diagrams

S. H 220909 Software Engineering Behavioral Diagrams

S. H 230009 Software Engineering Behavioral Diagrams

Statecharts ● A statechart diagram is a directed graph. The nodes of the graph represent states, and the arrows represent transitions between states caused by external events. Semantically this diagram says that if the current state of statechart machine M is STATE 1, then when EVENT 1 occurs, and if guard 1 is true, then actions effect 1 and effect 2 will be performed and the current state will become STATE 2. Upon entering STATE 2, M will perform action 1 and action 2. While the current state is STATE 2, M continually performs action 3. Upon exiting STATE 2, action 4 will be performed S. H 2009 Software Engineering Behavioral Diagrams

Example S. H 2009 Software Engineering Behavioral Diagrams

Example S. H 2009 Software Engineering Behavioral Diagrams

When to Use Statecharts ● They are good at describing the behaviour of an object across several scenarios of use. ● They are not good at describing behaviour that involves a number of collaborating objects (use interaction diagrams for this). ● Not usually worthwhile to draw a statechart for every class in the system. ● Use them only for those classes that exhibit interesting behaviour. S. H 2009 Software Engineering Behavioral Diagrams
- Slides: 34