Download presentation
Presentation is loading. Please wait.
Published byGeorgia Whitehead Modified over 9 years ago
1
מידול התנהגותי 1
2
Today’s Session Sequence Diagrams State Machines 2
3
Sequence Diagrams
4
Object Destruction obj2 : Class2 do (…) : Class3 create (…) obj1 : Class1 user operate() Object Creation Return Message foo() Messages to self Message Life line Sequence Diagrams 4 X-Axis (objects) Y-Axis (time)
5
Sequence Diagram Message Invokes an operation on an objectCall Returns a value to the callerReturn Sends a signal to an objectSend Create an objectCreate Destroys an objectDestroy Is the specification of a communication among objects that conveys information with the expectation that activity will ensue. : SomeClass 5
6
Syntax, Synchronous & Asynchronous What is the difference? (besides the Source / Source) a)b)c) 6
7
Conditions (Guards) and parameters 7
8
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
9
Structured control - alt 9
10
Structured control - opt 10
11
Structured control - loop 11
12
Nested diagrams 12 4: return value
13
State Modeling
14
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
15
Elements of a State Diagram 15 ElementsDescription UML Notation States The set of properties and values describing the object in a well defined instant. Initial State The initial state shows the starting point or first activity of the flow. Final State The final state corresponding completion transition on the enclosing state. History State A history state is used to remember the previous state of a state machine when it was interrupted Composite StateA composite state is a state that contains other states (sub-states). Transition A transition is a directed relation between a source state and a destination state. H
16
Transition 16 event –name [guard-condition] / action State 1 State 2 OpenClosed close OpenClosed close[balance=0] OpenClosed close[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
17
Transition 17 event –name [guard-condition] / action State 1 State 2 OpenClosed close OpenClosed close[balance=0] OpenClosed close[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
18
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.
19
Taking Class Example: Nested, Parallel States 19
20
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.
21
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
22
ATM - Solution 22
23
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
24
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
25
ATM (cont.) - Reducing Transitions Reducing transitions is important for: avoiding error prone situations and increasing readability. 25
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.