The learning objectives of this chapter are the followings. At the end of this chapter, you shall

Similar documents
Software Specification 2IX20

Object-Oriented Modeling. Sequence Diagram. Slides accompanying Version 1.0

Sequence Diagrams. Massimo Felici. Massimo Felici Sequence Diagrams c

Object-Interaction Diagrams: Sequence Diagrams UML

In this case, the behavior of a single scenario

Interaction Modelling: Sequence Diagrams

Object Interaction Sequence Diagrams

Unified Modeling Language

What is a Class Diagram? A diagram that shows a set of classes, interfaces, and collaborations and their relationships

What is a Class Diagram? Class Diagram. Why do we need Class Diagram? Class - Notation. Class - Semantic 04/11/51

Introduction to Unified Modelling Language (UML)

CS 370 REVIEW: UML Diagrams D R. M I C H A E L J. R E A L E F A L L

Specifying Precise Use Cases with Use Case Charts

Lecture 21 Detailed Design Dynamic Modeling with UML

Meltem Özturan

UML Behavioral Models

Object Oriented Methods with UML. Lecture -4

CSE 403. UML Sequence Diagrams. Reading: UML Distilled Ch. 4, by M. Fowler

CSE 308. UML Sequence Diagrams. Reading / Reference.

A Logical Framework for Sequence Diagram with Combined Fragments

UML Component Diagrams A.Y 2018/2019

6. Hoare Logic and Weakest Preconditions

Class diagrams. Modeling with UML Chapter 2, part 2. Class Diagrams: details. Class diagram for a simple watch

Software Engineering. Page 1. Objectives. Object-Behavioural Modelling. Analysis = Process + Models. Case Study: Event Identification

UML Sequence Diagrams

KF5008 Program Design & Development. Lecture 3 Sequence Diagrams

Chapter 2, Modeling with UML: UML 2 Hightlights

Interactions A link message

Semantics Preservation of Sequence

Specifying Precise Use Cases

Unified Modeling Language (UML) Object Diagram and Interaction Diagrams

Unit 5: Sequence Diagrams

3: Modeling Behavior with UML Sequence Diagrams

ETCS requirements specification and validation: the methodology

Sequence Diagrams. Sequence Diagrams. Version Sequence Diagrams are. History. simple powerful readable used to describe interaction sequences

UML 2.0 UML 2.0. Scott Uk-Jin Lee. Division of Computer Science, College of Computing Hanyang University ERICA Campus

Use Case Sequence Diagram. Slide 1

Orchestration vs Choreography

7. UML Sequence Diagrams Page 1 of 1

Distributed Systems. Lec 11: Consistency Models. Slide acks: Jinyang Li, Robert Morris

MATVEC: MATRIX-VECTOR COMPUTATION LANGUAGE REFERENCE MANUAL. John C. Murphy jcm2105 Programming Languages and Translators Professor Stephen Edwards

INTRODUCTION TO UNIFIED MODELING MODEL (UML) & DFD. Slides by: Shree Jaswal

Recap : UML artefacts. Black Box Requirements. Functional Specification. System. System. Test. Design. System. System. Development.

8. Control statements

Outline for Today CSE 142. CSE142 Wi03 G-1. withdraw Method for BankAccount. Class Invariants

Introduction to Model Checking

Chapter 10. Object-Oriented Analysis and Modeling Using the UML. McGraw-Hill/Irwin

Model Based Software Timing Analysis Using Sequence Diagram for Commercial Applications

Cantor s Diagonal Argument for Different Levels of Infinity

Semantics with Applications 3. More on Operational Semantics

Tool Support for Design Inspection: Automatic Generation of Questions

Handout 9: Imperative Programs and State

CS211 Lecture: Modeling Dynamic Behaviors of Systems; Interaction Diagrams and Statecharts Diagrams in UML

CS211 Lecture: Modeling Dynamic Behaviors of Systems; Interaction Diagrams in UML

Enterprise Architect. User Guide Series. Testpoints. Author: Sparx Systems. Date: 30/06/2017. Version: 1.0 CREATED WITH

Class diagrams. Modeling with UML Chapter 2, part 2. Class Diagrams: details. Class diagram for a simple watch

A Role-based Use Case Model for Remote Data Acquisition Systems *

Today s Agenda UML. CompSci 280 S Introduction to Software Development. 1.Introduction UML Diagrams. Topics: Reading:

AXIOMS OF AN IMPERATIVE LANGUAGE PARTIAL CORRECTNESS WEAK AND STRONG CONDITIONS. THE AXIOM FOR nop

Introduction Distributed Systems

Compiler Theory. (Semantic Analysis and Run-Time Environments)

BASICS OF UML (PART-2)

Run-time Environments. Lecture 13. Prof. Alex Aiken Original Slides (Modified by Prof. Vijay Ganesh) Lecture 13

12 Tutorial on UML. TIMe TIMe Electronic Textbook

SE Assignment III. 1. List and explain primitive symbols used for constructing DFDs. Illustrate the use of these symbols with the help of an example.

Requirements Checking for Object-Oriented Software Design with different Unified Modelling Language (UML) notations

CIS 500 Software Foundations. Final Exam. May 3, Answer key

Joint Entity Resolution

Applying UML & Patterns (3 rd ed.) Chapter 15

Process Modelling. Fault Tolerant Systems Research Group. Budapest University of Technology and Economics

Review of the C Programming Language

Combining Sequence Diagrams and OCL for Liveness

4/6/2011. Model Checking. Encoding test specifications. Model Checking. Encoding test specifications. Model Checking CS 4271

Definition. A set is a collection of objects. The objects in a set are elements.

1.2 Venn Diagrams and Partitions

Object-Oriented Analysis and Design. Pre-UML Situation. The Unified Modeling Language. Unification Efforts

Weaving Multiple Aspects in Sequence Diagrams

Qualifying Exam in Programming Languages and Compilers

UML class diagrams. Nigel Goddard. School of Informatics University of Edinburgh

BUILDING BLOCKS. UML & more...

Statecharts 1.- INTRODUCTION 1.- INTRODUCTION

Lecturer 2: Spatial Concepts and Data Models

Sequence Diagram. r: Register s: Sale

Sequence Diagram. A UML diagram used to show how objects interact. Example:

Propositional Logic. Part I

Some notes about Event-B and Rodin

Object Oriented Modeling

Relationships between UML Sequence Diagrams and the Topological Functioning Model for Backward Transformation

UML Sequence Diagrams for Process Views

SETS. Sets are of two sorts: finite infinite A system of sets is a set, whose elements are again sets.

Distributed Systems Programming (F21DS1) Formal Verification

UML- a Brief Look UML and the Process

Refining UML specifications. - the STAIRS method. Ragnhild Kobro Runde. Joint work with Ketil Stølen and Øystein Haugen. Ragnhild Kobro Runde

Review of the C Programming Language for Principles of Operating Systems

Selections. EECS1021: Object Oriented Programming: from Sensors to Actuators Winter 2019 CHEN-WEI WANG

3.7 Denotational Semantics

Taibah University College of Computer Science & Engineering Course Title: Discrete Mathematics Code: CS 103. Chapter 2. Sets

Dataflow Processing. A.R. Hurson Computer Science Department Missouri Science & Technology

Week 9 Implementation

Abstract Interpretation

Transcription:

Chapter 5 Sequence diagrams In the previous chapters, we have seen different diagrams. Use case diagrams describe tasks that a system is supposed to perform. It gives high-level information about how a user should interact with the system. Class diagrams specify the structure and the operations related to the data used by the system. A sequence diagram can help specifying the link between a use case and the methods and classes defined in class diagrams. It is therefore important to ensure consistency between these three kinds of diagrams. 5.1 Learning objectives of this chapter The learning objectives of this chapter are the followings. At the end of this chapter, you shall know what is a UML sequence diagram; be capable of creating detailed UML sequence diagrams; be capable to ensure consistency between sequence, class, and use case diagrams. 5.2 Sequence diagram 5.2.1 Overview and some definitions A sequence diagrams basically shows how actors and objects interact to realise a use case scenario. Figure 5.1 shows a simple sequence diagram. It focuses on the message exchange between a number of lifelines. Lifeline A lifeline represent the lifetime of a participant in the interaction. A lifeline can be an actor, a class, or any object involved in the use case. In a lifeline time starts at the top and increases as we go down the lifeline. Regarding notation: 35

36 CHAPTER 5. SEQUENCE DIAGRAMS Figure 5.1: A simple sequence diagram. actors will be denoted by their name or using the usual UML pictogram for actors; a class A will be denoted by a rectangle named :A; an object anobject of class A will be denoted by a rectangle named anobject:a. Figure 5.2: A short sequence diagram. Figure 5.2 shows an example of a simple sequence diagram. In this sequence diagram, an actor first sends a message msg 1 to an instance of class A. After that, class A sends a message msg 2 to an instance of class B. Finally, B sends a response to A, that sends a response to the actor.

5.2. SEQUENCE DIAGRAM 37 The intuition behind sending a message is that sending a message means calling a given method of a class. In Figure 5.2, this means that the actor is calling method named msg 1 from class A. This also means that class A must have a method named msg 1. A similar remark holds for method msg 2 of class B. There is an implicit rule that a message is sent before it is received. The rectangles are called activations. An activation specifies that a lifeline is active. Figure 5.3: Self activation. As shown in Figure 5.3, a lifeline can activate itself. The activation is then shown with a slight offset. This is used to represent computations executed by the lifeline. Note that only actors can send messages out-of-the-blue. Actors initiate interactions with the system. The system and its objects only react to actors stimuli. 5.2.2 Semantics The UML standard sketches the semantics of sequence diagrams using event traces. Every time a message is sent and received, this creates two events, namely, a send event and a receive event. A trace is a possibility infinite sequence of events. The semantics of a diagram is defined by two sets of traces: 1. A set of valid traces, that is, the traces representing valid behaviours; 2. a set of invalid traces, that is, the traces representing invalid behaviours. The invalid behaviours are used to define some operators (like neg, see later in this chapter). Most of the times, the semantics are defined by the valid behaviours. We will not attempt to formalise the semantics any further. We intentionally as it is done in the UML standard remain at the level of natural language and intuition. Intuitively, the semantics of the diagram in Figure 5.2 is message msg1 is sent and received, message msg2 is then sent and received, message response is sent and received, an un-named message is sent and received.

38 CHAPTER 5. SEQUENCE DIAGRAMS 5.2.3 Synchronous vs. Asynchronous communications If there is no concurrency, exactly one object is active or computing at any given instant. In that case, activation computations behave like a stack. Figure 5.4: Asynchrony and concurrency. Figure 5.4 shows asynchronous communications and introduces concurrency, that is, two lifelines are active at the same instant. As emphasised in the picture, you should notice the difference in the arrow-head of the arrow labelled msg2. This type of arrow indicates an asynchronous communication. The lifeline emitting the message or calling a particular method remains active after sending the message. In this example, once msg2 is sent, both class A and class B are active. 5.3 Object creation and destruction It is possible to indicate creation and destruction of objects. Figure 5.5 shows an example. A creation action is done using an asynchronous arrow as the creator is still active after creation. The creator should not have to wait that the created object terminates to resume execution. Notice that by convention destruction of objects uses synchronous messages. 5.4 Operators The UML standard defines several operators than can be used to further specify lifelines and their interactions. In this course, we cover a subset only of all the possible operators.

5.4. OPERATORS 39 Figure 5.5: Creation and destruction. Figure 5.6: Overview operator syntax.

40 CHAPTER 5. SEQUENCE DIAGRAMS Figure 5.6 shows an overview of the operator syntax. As it can be seen in the picture, an operator has zero or more conditions, and one or more operands. An operator defines a combined fragments composed of the different operands. Each operand defines an area with a different behaviour. 5.4.1 Alternatives: alt Figure 5.7: Illustration of the alt operator. Operator alt introduces a combined fragment expressing possible alternatives over the lifelines. The alt operator has one or more conditions and one operand per condition plus an default operand in the case that all conditions are false. The intuition is similar to case- or if-statements in programming languages. If a condition holds, execute the corresponding operand; else, execute the second fragment. Figure 5.7 shows an example. If the balance is enough then the transaction can be processed, else the transaction is cancelled. The semantics is defined as adding the union of the traces of the operands to the set of valid traces. Note that if more than one condition is true, the first one (most top in the lifeline) is executed. 5.4.2 Option: opt Operator opt introduces an optional fragment. It is equivalent to an alt operator where the else-operand is empty. The intuition is that if the condition holds, the frag-

5.4. OPERATORS 41 ment is executed; else, simply skip the fragment and continue. Figure 5.8: Alt and Opt operators. Figure 5.8 summarises the differences between operators alt and opt. 5.4.3 Loop and break Figure 5.9 shows the syntax for loop and break operators. A loop operator allows you to model iteration. When the break condition is true, the break operand executes and the loop terminates. There are different loop types summarised in Figure 5.10. 5.4.4 Combining operators: par, seq, strict Figure 5.11 shows different ways of combining operators. par: the par operator expresses the parallel execution of its operands. Each operand is executed in parallel to the others. Within an operand, the order of execution of this operand is preserved. The semantics is therefore the set of all possible inter-leavings between the operands. seq: the seq operator defines a weak sequential execution between its operands. The order of execution within an operand is maintained. The difference with the par operator is that the execution order is also maintained within a lifeline. As

42 CHAPTER 5. SEQUENCE DIAGRAMS Figure 5.9: Loop and Break operators. Figure 5.10: Summary of the different types of loops.

5.4. OPERATORS 43 Figure 5.11: Summary of the different types of sequencing operators. shown in Figure 5.11, searching with Bing is always performed before searching with Yahoo. strict: the strict operator defines sequential execution. Here the order of execution is maintained within operands, lifelines and also over different lifelines. Figure 5.12: Definition of a co-region.. An simpler notation equivalent to par is to define a co-region as illustrated in Figure 5.12. This sequence diagram is equivalent to the most left diagram in Figure 5.11. 5.4.5 Negation: neg The neg operator defines invalid behaviours, that is, behaviours that should not happen. The semantics is that traces of the neg operands are added to the set of invalid traces. Figure 5.13 shows a simple example. The intuition is that the system should never produce a timeout message.

44 CHAPTER 5. SEQUENCE DIAGRAMS Figure 5.13: Simple neg operator example. 5.5 Invariants and duration constraint 5.5.1 Invariants It is possible to state invariants on lifelines. Invariants are evaluated prior to the next activation specification. All traces for which the invariants hold are valid. Otherwise, traces are invalid. Figure 5.14: A simple invariant. Figure 5.14 shows an example. The invariant will be checked at the end of the activation specification. Invariants can also be stated on a lifeline. It has the same meaning. Traces of the lifelines are valid if and only if the invariant holds. Figure 5.15 shows an example. Only traces with a positive balance are valid. 5.6 Conclusion This chapter has introduced Sequence Diagrams as means to specify interactions between structural elements of a system and the environment of a system. Sequence diagrams therefore support the specification of sequences of events required to achieved

5.7. EXERCISES 45 Figure 5.15: A lifeline with an invariant. user goals and post-condition of use cases. Sequence diagrams must be kept consistent with both use case diagrams and class diagrams. 5.7 Exercises Exercise 5.7.1. Consider the specification of the UML-Bookshop in Exercise 3.7.1 and Exercise 4.5.1. Using the class diagram and the use case diagram you produced, draw a sequence diagram based on one of the use cases. Exercise 5.7.2. Consider the specification of the transport company in Exercise 3.7.2 and Exercise 4.5.2. Using the class diagram and the use case diagram you produced, draw a sequence diagram based on one of the use cases. Exercise 5.7.3. Consider the specification of the embedded system of the railway controller in Exercise 3.7.3 and Exercise 4.5.3. Using the class diagram and the use case diagram you produced, draw a sequence diagram based on one of the use cases. Exercise 5.7.4. Consider your preferred webshop. Draw a sequence diagram representing the interaction sequence you need to execute to order an item.

46 CHAPTER 5. SEQUENCE DIAGRAMS