Spring 2007 Modeling Behavior with UML Sequence Diagrams

Spring 2007 Modeling Behavior with UML Sequence Diagrams Eran Toch http: //www. technion. ac. il/~erant Specification and Analysis of Information Systems Spring 2005 1

Outline • • Introduction Basic notation Alternating paths Modularity 2

Modeling Process Phase Actions Outcome Business documents Initiation Raising a business need Requirements Interviewing stakeholders, exploring the Organized system environment documentation Specification Analyze the engineering aspect of the system, building system concepts Formal specification Design Define architecture, components, data types, algorithms Formal Specification Implementation documentation Program, build, unit-testing, integrate, Testable system Testing & Integration Integrate all components, verification, validation, installation, guidance Testing results, Working sys Maintenance Bug fixes, modifications, adaptation System versions Introduction | Basics | Alternations | Modularity 3

Why to Model Behavior? • How do we use the SMS Server interface? What is the order of executing the operations? – send. Message, get. Status, Resend? – get. Status, send. Message, check. For. Messages? • When do we use resend? Introduction | Basics | Alternations | Modularity 4

Behavioral Modeling • Where are people coming from ? • Where are they going? • How do they move from one space to the other? Introduction | Basics | Alternations | Modularity 5

Behavior Modeling Sequence Diagrams Checkout Manager Activity Diagrams Order Add to cart message: create In process Check availability Order message: change status State Diagrams [problem] supplied [okay] Inventory Notify User Supply Order * We will not talk about collaboration diagrams Introduction | Basics | Alternations | Modularity 6

Outline • • Introduction Basic elements Alternating paths Modularity 7

Building a Sequence Diagrams Sequence diagrams capture the use-case behavior using the foundation of the classes. Use Case 1 Class A Class C Use Case 3 Use Case 2 Class D Class B therefore Sequence = Introduction | Basics | Alternations | Modularity Objects + messages 8

Sequence Diagrams • A simple sequence diagram: objects sd Product Buying Diagram Name p : Product : Shoopping. Cart customer display() message get. Price() activation (focus of control) add. Product (p) checkout () Life line Introduction | Basics | Alternations | Modularity 9

Object Control obj 1 : Class 1 obj 2 : Class 2 user Object Creation operate() do (…) create (…) : Class 3 Return Messages to self foo() Object Destruction Illustration Introduction | Basics | Alternations | Modularity 10

Corresponding Class Diagram Notice that a dependency exists whenever messages are passed between instances of the class Dependencies can be overridden by associations, aggregations etc. Illustration Introduction | Basics | Alternations | Modularity 11

Sequences and Use-Cases p : Product : Shoopping. Cart customer display() get. Price() add. Product (p) checkout () create (…) : Order Visible part Introduction | Basics | Alternations | Modularity Hidden part 12

13
![Full Message Attributes [sequence-expression] [return-value : =] [message-name] [(argument-list)] C 3. 1: res : Full Message Attributes [sequence-expression] [return-value : =] [message-name] [(argument-list)] C 3. 1: res :](http://slidetodoc.com/presentation_image_h/07f9d503732276d674cb7db70ffd07d5/image-14.jpg)
Full Message Attributes [sequence-expression] [return-value : =] [message-name] [(argument-list)] C 3. 1: res : = get. Location (fig) sequence number message name argument list return value Introduction | Basics | Alternations | Modularity 14

Different Kinds of Messages Synchronous Message asynchronous Message Return Message Introduction | Basics | Alternations | Modularity 15

Synchronous & Asynchronous Messages Nested Flow teller : Order Asynchronous Flow : Article get. Value appl err handl alarm unknown ring price set. ID log Example Price need to be finished, before teller can do another operation (get. Name) Introduction | Basics | Alternations | Modularity Example Ring is executed, while the control flow is returned to err handle and appl 16

Outline • • Introduction Basic elements Alternating paths Modularity 17

Flow Constructs If Loop Else Repeat Jump When we tell a scenario, which types of alternatives do we need? Introduction | Basics | Alternations | Modularity 18
![Options msg : Message : Database Fragment opt [msg. status=confirmed] Condition archive(msg) Do something. Options msg : Message : Database Fragment opt [msg. status=confirmed] Condition archive(msg) Do something.](http://slidetodoc.com/presentation_image_h/07f9d503732276d674cb7db70ffd07d5/image-19.jpg)
Options msg : Message : Database Fragment opt [msg. status=confirmed] Condition archive(msg) Do something. . . Used for modeling simple optional blocks. Has one operand; no "else" guard. Example Introduction | Basics | Alternations | Modularity 19
![Alternatives msg : Message : Database : Admin alt [msg. status=confirmed] archive(msg) Alternative Fragment Alternatives msg : Message : Database : Admin alt [msg. status=confirmed] archive(msg) Alternative Fragment](http://slidetodoc.com/presentation_image_h/07f9d503732276d674cb7db70ffd07d5/image-20.jpg)
Alternatives msg : Message : Database : Admin alt [msg. status=confirmed] archive(msg) Alternative Fragment group Condition [msg. status=error] notify(msg. get. ID()) [else] Else condition (optional) wait() Introduction | Basics | Alternations | Modularity Execution regions. At most one will execute. 20
![Loops : OS : Folder : File loop Loop Fragment [for each Folder] Display() Loops : OS : Folder : File loop Loop Fragment [for each Folder] Display()](http://slidetodoc.com/presentation_image_h/07f9d503732276d674cb7db70ffd07d5/image-21.jpg)
Loops : OS : Folder : File loop Loop Fragment [for each Folder] Display() loop Condition [for each File] Display() Nested Loop Fragment Introduction | Basics | Alternations | Modularity 21

Breaks : User Manager : Policy is. Looged = login(name, pass) If the condition is met, the break fragment is executed, and the reminder of the sequence is ignored break [¬is. Looged] add. Bad. Login(name) Do something… Do something … Introduction | Basics | Alternations | Modularity Handy in model exception handling 22
![Examples of Guards • • • ]for each Object[ [5] ]i=1. . 5[ ]status Examples of Guards • • • ]for each Object[ [5] ]i=1. . 5[ ]status](http://slidetodoc.com/presentation_image_h/07f9d503732276d674cb7db70ffd07d5/image-23.jpg)
Examples of Guards • • • ]for each Object[ [5] ]i=1. . 5[ ]status = okay[ No guard means an infinite loop Introduction | Basics | Alternations | Modularity 23

Outline • • Introduction Basic elements Alternating paths Modularity 24

Modularity We need ways to create modular scenarios Introduction | Basics | Alternations | Modularity 25

Referencing a diagram : User Manager login(name, pass) : Policy ref Login Handling(user, pass) : bool Reference Gate Do something… Do something … Introduction | Basics | Alternations | Modularity 26

Referenced Diagram name sd Login Handling : User Manager : User. Account loop Input message login(name, pass) [for each User. Account] c. Name -= get. Use. Namer() opt Output message [c. Name = name] is. In. System(true) true false Introduction | Basics | Alternations | Modularity 27

Parallel Fragments : Checkout Handler : User : Shipping Handler : Transaction Handler provide. Details(…) perform. Checkout() par Ship(address, products) charge. Money(CC, sum) Introduction | Basics | Alternations | Modularity 28

Critical Fragment • the region is treated atomically by the enclosing fragment (i. e. parallel fragment) • No other operations can interfere while a critical region is executed Introduction | Basics | Alternations | Modularity 29

Summary ü Behavior Modeling Sequence models interaction ü Language Objects + lifeline Messages ü Alternations Loops Alternatives ü Modularity Referencing Parallel Introduction | Basics | Alternations | Modularity 30
- Slides: 30