Sequence diagram 1 Models overview Soft Systems Model

  • Slides: 27
Download presentation
Sequence diagram 1

Sequence diagram 1

Models overview Soft Systems Model Use case model Sequence diagram Activity diagram per use

Models overview Soft Systems Model Use case model Sequence diagram Activity diagram per use case Class diagram 2

How to model dynamic behavior of your application? • Use Case Diagram – high-level

How to model dynamic behavior of your application? • Use Case Diagram – high-level behaviors of the system, user goals, external entities: actors • Activity Diagram – flow of control between activities • Interaction diagrams - model how groups of object collaborate to perform some behavior (typically capture the behavior of a single use case) – Sequence Diagram – focus on time ordering of messages – Collaboration/Communication Diagram – focus on structural organization of objects and messages 3

Interaction diagrams • UML specifies a number of interaction diagrams to model dynamic aspects

Interaction diagrams • UML specifies a number of interaction diagrams to model dynamic aspects of the system • Typically used during analysis and design to document and understand the logical flow of your system • Interaction Diagrams - Set of objects or roles and the messages that can be passed among them. – Sequence Diagrams - emphasize time ordering – Communication Diagrams - emphasize structural ordering 4

What is sequence diagram? • Sequence diagram is an "interaction diagram" that models object

What is sequence diagram? • Sequence diagram is an "interaction diagram" that models object interactions in a given scenario identified for a given Use Case. • What is scenario? – A scenario is a sequence of events that occurs during one particular execution of a system. 5

Key parts of a sequence diagram • • • Participant : an object or

Key parts of a sequence diagram • • • Participant : an object or entity that acts in the sequence diagram Message: communication between participant objects The axes in a sequence diagram: – horizontal: which object/participant is acting – vertical: time (down -> forward in time) 6

Message Connections • The arrow indicates that: – The sender sends a message –

Message Connections • The arrow indicates that: – The sender sends a message – The receiver receives the message – The receiver takes some action, returning the result to the sender The message must activate an operation in the receiving object 7

Sequence diagram notation: Lifelines : Object 1 : Object 2 Lifelines: Identify the existence

Sequence diagram notation: Lifelines : Object 1 : Object 2 Lifelines: Identify the existence of the object over time. 8

Sequence diagram notation: Sequence : Object 1 : Object 2 message Sequence: Vertical position

Sequence diagram notation: Sequence : Object 1 : Object 2 message Sequence: Vertical position signifies chronological sequence – earlier messages appear nearer the top. 9

Sequence diagram notation: Activations : Object 1 : Object 2 Activations: Indicate when an

Sequence diagram notation: Activations : Object 1 : Object 2 Activations: Indicate when an object is performing an action 10

Sequence diagram notation: Messages : Object 1 : Object 2 message Messages: Indicate the

Sequence diagram notation: Messages : Object 1 : Object 2 message Messages: Indicate the communications between objects 11

Types of messeges • Synchronous Messages - Sender waits for response to message before

Types of messeges • Synchronous Messages - Sender waits for response to message before doing anything more. 12

An example of Synchronous Messages 13

An example of Synchronous Messages 13

Asynchronous Message • Used when the sender does not have to wait for a

Asynchronous Message • Used when the sender does not have to wait for a response – Typically an one way message – No response is sent 14

Message to self • Self-Call: A message that an object sends to itself. 15

Message to self • Self-Call: A message that an object sends to itself. 15

Conditional interaction • Condition indicates when a message is sent – the message is

Conditional interaction • Condition indicates when a message is sent – the message is sent only if the condition is true 16

“opt” Combined Fragment • The if-then Statement -> (opt) [condition] void apply. Brakes() {

“opt” Combined Fragment • The if-then Statement -> (opt) [condition] void apply. Brakes() { // the "if" clause: bicycle must be moving if (is. Moving){ // the "then" clause: decrease current speed current. Speed--; } } 17

“alt” Combined Fragment • The if-then-else Statement -> (alt) [condition] - separated by horizontal

“alt” Combined Fragment • The if-then-else Statement -> (alt) [condition] - separated by horizontal dashed line class If. Else. Demo { public static void main(String[] args) { int testscore = 76; char grade; if (testscore >= 91) { grade = 'A'; } else if (testscore >= 81) { grade = 'B'; } else if (testscore >= 71) { grade = 'C'; } else if (testscore >= 61) { grade = 'D'; } else { grade = 'F'; } System. out. println("Grade = " + grade); } } 18

Repeated interaction 19

Repeated interaction 19

“loop” Combined Fragment • While -> (loop) [condition or items to loop over] while

“loop” Combined Fragment • While -> (loop) [condition or items to loop over] while (true) { // your code goes here } 20

Linking sequence diagrams • If one sequence diagram is too large or refers to

Linking sequence diagrams • If one sequence diagram is too large or refers to another diagram, indicate it with either: – a "ref" frame that names the other diagram (Fig. 1) – an unfinished arrow and comment (Fig. 2) Fig. 1. “ref” frame Fig. 2. Another way of ref. 21

Task 1: Draw the following sequence diagram using RSA 22

Task 1: Draw the following sequence diagram using RSA 22

Steps • • • File > New > Project Select UML Project (under Modeling)

Steps • • • File > New > Project Select UML Project (under Modeling) Give the name of the project: – Project name: Exercise_Sequence – Click Next • • Click on General, and then on Blank Package (selected by default) Give the name to the package: – File name: Exercise_Sequence – Click Finish • In the Project Explorer View, expand Exercise Sequence, and under Models, click on created package Exercise_Sequence – Right click on that package and click on Add Diagram, and select Sequence diagram. – Name the Sequence diagram as: sd. Exercise_Sequence • Using the elements from the Palette View, draw the desired diagram 23

Task 2: Create sequence diagram sd. User. Login § The user, as an actor,

Task 2: Create sequence diagram sd. User. Login § The user, as an actor, enters credentials into the Log. In form. § The Log. In form forwards user’s credentials to the application. § The application checks whether the user exists in the database. § If the user doesn’t exist in the database, the application notifies the user via the Log. In form. § If the password is incorrect, the application notifies the user via the Log. In form. § If everything is correct, the application welcomes the user with a message via the Log. In form. 24

25

25

Task 2: Create sequence diagram sd. Voting § The Citizen (as an actor) chooses

Task 2: Create sequence diagram sd. Voting § The Citizen (as an actor) chooses voting option on the webpage Voter. User. Form <<user interface, UI>> § Voter. User. Form forwards the received information to the application (<<controller>> Voting) § In the database, it is checked whether the user has already voted (<<Table>> Votes). § If the user has voted, then the application notifies the user that there is no possibility for re-voting. The application does so via the Voter. User. Form. § If the user has not voted: • The application retrieves the list of all the candidates from the database (<<Table>> Candidates) • The list of candidates is presented to the user via the Voter. User. Form. • The user selects a candidate and the application updates the information in the database accordingly *. 26

27

27