מידול התנהגותי 1. today’s session sequence diagrams state machines 2

25
תתתתת תתתתתת תתתתתת תתתתת תתתת2012 ייייי יייייייי1

Upload: georgia-whitehead

Post on 11-Jan-2016

223 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: מידול התנהגותי 1. Today’s Session Sequence Diagrams State Machines 2

ניתוח ועיצוב מערכות תוכנה

2012אביב התנהגותי מידול

1

Page 2: מידול התנהגותי 1. Today’s Session Sequence Diagrams State Machines 2

Today’s Session

Sequence Diagrams

State Machines

2

Page 3: מידול התנהגותי 1. Today’s Session Sequence Diagrams State Machines 2

Sequence Diagrams

Page 4: מידול התנהגותי 1. Today’s Session Sequence Diagrams State Machines 2

Object Destruction

obj2 : Class2

do)…(

:Class3create)…(

obj1 : Class1

useroperate)(

Object Creation

Return Message

foo)(

Messages to self

Message

Life line

Sequence Diagrams

4

X-Axis (objects)

Y-Ax

is (ti

me)

Page 5: מידול התנהגותי 1. Today’s Session Sequence Diagrams State Machines 2

Sequence Diagram Message

Invokes an operation on an object Call

Returns a value to the caller Return

Sends a signal to an object Send

Create an object Create

Destroys an object Destroy

Is the specification of a communication among objects that conveys information with the expectation that activity will ensue.

:SomeClass

5

Page 6: מידול התנהגותי 1. Today’s Session Sequence Diagrams State Machines 2

Syntax, Synchronous & Asynchronous What is the difference?(besides the Source / Source)

a) b) c)

6

Page 7: מידול התנהגותי 1. Today’s Session Sequence Diagrams State Machines 2

Conditions (Guards) and parameters

7

Page 8: מידול התנהגותי 1. Today’s Session Sequence Diagrams State Machines 2

Structured controls (combined fragments)

Structured control Meaning

alt Alternative fragment for mutual exclusion conditional logic expressed in the guards (if... then... else).

opt Optional fragment that executes if guard is true.

par Parallel fragments that execute in parallel.

ref Refers to an interaction defined in another diagram.

loop The fragment may execute multiple times, and the guard indicates the basis of iteration

summarization of some common frame operators

8

Page 9: מידול התנהגותי 1. Today’s Session Sequence Diagrams State Machines 2

Structured control - alt

9

Page 10: מידול התנהגותי 1. Today’s Session Sequence Diagrams State Machines 2

Structured control - opt

10

Page 11: מידול התנהגותי 1. Today’s Session Sequence Diagrams State Machines 2

Structured control - loop

11

Page 12: מידול התנהגותי 1. Today’s Session Sequence Diagrams State Machines 2

Nested diagrams

12

4: return value

Page 13: מידול התנהגותי 1. Today’s Session Sequence Diagrams State Machines 2

State Modeling

Page 14: מידול התנהגותי 1. Today’s Session Sequence Diagrams State Machines 2

What’s Missing in Behavior Modeling?Using an interaction, you can model the behavior of a set of objects that

work together.

Using a state machine, you can model the behavior of an individual object whether its an instance of a class, use case, or even an entire system (a set of classes).

The behavior of an object that must respond to asynchronous messages or whose current behavior depends on its past is best specified by a state machine.

We need some language for modeling the behavior of an individual object, in order to: Model how an object responds to events Enumerate the possible states of an object Model how the history of an object can affect its behavior

14

Page 15: מידול התנהגותי 1. Today’s Session Sequence Diagrams State Machines 2

Elements of a State Diagram

15

Elements Description UML Notation

StatesThe set of properties and values describing the object in a well defined instant.

Initial StateThe initial state shows the starting point or first activity of the flow.

Final StateThe final state corresponding completion transition on the enclosing state.

History StateA history state is used to remember the previous state of a state machine when it was interrupted

Composite State A composite state is a state that contains other states (sub-states).

TransitionA transition is a directed relation between a source state and a destination state.

H

Page 16: מידול התנהגותי 1. Today’s Session Sequence Diagrams State Machines 2

Transition

16

event –name [guard-condition] / actionState 1 State 2

Open Closedclose

Open Closedclose[balance=0]

Open Closedclose[balance=0]/moveToArchive)(

The event that triggers the transition

Conditions that must be met for the transition to take place.

The action that takes place when the transition is taken

Page 17: מידול התנהגותי 1. Today’s Session Sequence Diagrams State Machines 2

Transition

17

event –name [guard-condition] / actionState 1 State 2

Open Closedclose

Open Closedclose[balance=0]

Open Closedclose[balance=0]/moveToArchive)(

The event that triggers the transition

Conditions that must be met for the transition to take place.

The action that takes place when the transition is taken

Page 18: מידול התנהגותי 1. Today’s Session Sequence Diagrams State Machines 2

States: Initial, Transitions and Final

18

Initialize variables on the action clause of the initial pseudo-state transition.

after )2 seconds( / send ping signal

/target = null

targetAt)p( [isThreat)p(] / addTarget)p(

Sometimes tm is used instead of ‘after’, indicating ‘timer’. )i.e. tm)2 seconds(.The timer is individual per state, and is restarted upon each entry.

Page 19: מידול התנהגותי 1. Today’s Session Sequence Diagrams State Machines 2

Taking Class Example: Nested, Parallel States

19

Page 20: מידול התנהגותי 1. Today’s Session Sequence Diagrams State Machines 2

Self Transition and Internal Action

20

If occurrence event1

then calls: Activity3,

Activity1, Activity2

If occurrence event1

then calls:Activity1

?

A state can also define a “ do/Activity” clause – an activity performed during the state; the activity is interrupted when a transition fires.

Page 21: מידול התנהגותי 1. Today’s Session Sequence Diagrams State Machines 2

ATM (History, Aggregated Transitions) Model an ATM that can:

1. Wait for customers.2. Be in maintenance mode (for instance: when replenishing the cash store).3. Upon insertion of a credit card it will validate the card and process the

client requests.4. The former action can be cancelled before completion.

21

Page 22: מידול התנהגותי 1. Today’s Session Sequence Diagrams State Machines 2

ATM - Solution

22

Idle entry / readCardexit / ejectCard

Active

Selecting

[more]

exit / displayFinishedPrinting

[finished]

Processing

[more]

[finished]

Validating

Maintenance

Selecting

[more]

exit / displayFinishedPrinting

[finished]

Processing

[more]

[finished]

Validating

exit / displayFinishedPrinting

Validating Selecting

Processing

mainten

cardInserted

cancel

[more]

[finished]

Visual Paradigm for UML Standard Edition)Ben Gurion University(

Page 23: מידול התנהגותי 1. Today’s Session Sequence Diagrams State Machines 2

Idle entry / readCardexit / ejectCard

Active

Selecting

[more]

exit / displayFinishedPrinting

[finished]

Processing

[more]

[finished]

Validating

Maintenance

Selecting

[more]

exit / displayFinishedPrinting

[finished]

Processing

[more]

[finished]

Validating

exit / displayFinishedPrinting

Validating Selecting

Processing

mainten

cardInserted

cancel

[more]

[finished]

Visual Paradigm for UML Standard Edition)Ben Gurion University(

History

1. Notice that real-life ATM machines do not have history! This is just an example.2. In this case there is no difference between shallow and deep history.

23

H

Page 24: מידול התנהגותי 1. Today’s Session Sequence Diagrams State Machines 2

ATM (cont.)What if we wanted to state that from every state in the “active” composite

state you can transition to the “selecting” state upon a certain event?

24

H

Page 25: מידול התנהגותי 1. Today’s Session Sequence Diagrams State Machines 2

ATM (cont.) - Reducing Transitions

Reducing transitions is important for: avoiding error prone situations and increasing readability.

25

Idle entry / readCardexit / ejectCard

Active

Selecting

[more]

small cancel

exit / displayFinishedPrinting

[finished]

Processing

[more]

[finished]

Validating

Maintenance

Selecting

[more]

small cancel

exit / displayFinishedPrinting

[finished]

Processing

[more]

[finished]

Validating

exit / displayFinishedPrinting

Validating Selecting

Processing

mainten

cardInserted

cancel

[more]

[finished]

small cancel

Visual Paradigm for UML Standard Edition)Ben Gurion University(