Presentation is loading. Please wait.

Presentation is loading. Please wait.

UML Discussion on State Machines Perfectly static system is intensely uninteresting Because nothing ever happens.

Similar presentations


Presentation on theme: "UML Discussion on State Machines Perfectly static system is intensely uninteresting Because nothing ever happens."— Presentation transcript:

1

2 UML Discussion on State Machines

3 Perfectly static system is intensely uninteresting Because nothing ever happens

4 Real Systems Dynamic in nature and always something is happening internally or externally. ATM Machine. Robot. Chemical Reaction. Network Router.

5 Objects Objects work together to realize higher-order behaviors defined by use cases. Object Behavior with respect to time Simple State Continuous

6 What is State Machine Its abstract It has finite state of conditions of existence called states It has set of actions performed in each state It has set of events which causes state change to well defined rule set.

7 State Machine Example Possible States RED YELLOW GREEN Flashing Yellow Flashing Red …

8 What things exhibit state ? Classes Use cases State Machine can be applied to object oriented systems as well as functionally decomposed ones.

9 Behavioral Elements

10 State Transition State Machine Guard Event

11

12 State Machine Using state machine you can Model behavior of individual object. State Machine illustrates sequential behavior of object.  Statechart Diagrams. ­State to State.  Activity Diagrams. ­Activity to Activity.

13 Example Payment Authorization Authorizing Authorized Delivered Rejected

14 Web Application  Not yet logged in. Action: Display the login page  Logged in and viewing the account balance Display the account balance Display logout button, and view transaction button.  Logged in and viewing recent transactions Display recent transactions Display logout button, and view account balance button.  Logged out Display “Goodbye page”

15

16 Validate Login/PIN

17 Word Processing

18 Brew Controller of coffee machine

19 Coffee Machine Tank

20 Sequential Sub states

21 Concurrent Substates

22 Food For Thought…. Identify States

23 Hypothetical State Machine Event Queue  When event is received it is placed in queue of target Event Dispatcher  When delivered to state machine Event Processor  Consumed and event is complete

24 State Machine Concepts Context  An association to the model element that whose behavior is specified by this state machine States Transitions Event

25 State Machine Concepts Context States  models a situation during which some (usually implicit) invariant condition holds. Transitions Event

26 State Simple State  No Substates Initial State  Object comes into being Final State  The entire state machine has completed  A final state cannot have any outgoing transitions

27 State Machine Concepts Context States Transitions  A transition is a directed relationship between a source state and target state Event

28 Transition Guard Trigger Source Target Effects

29 Guard A guard is a Boolean expression that is attached to a transition as a fine-grained control over its firing.  If the guard is true at that time, the transition is enabled, otherwise, it is disabled.

30 State Machine Concepts Context States Transitions Event  An event is a specification of a type of observable occurrence

31

32 Events Call Event  Reception of request to synchronously invoke operation. ­Creation of object ­Deletion of object Time Event  Models expiration of specific deadline.

33 Events… Signal Event  Reception of asynchronous signal

34

35 Events… Change Event  Implicit  Results as a change in some value of object attribute

36 Practical Implementations Mapping of Statechart to efficient code Common Approaches  Double Nested Switch Statements  Action state tables  Generic state machine interpreters  State Patterns in OO Paradigm

37

38 /* States. */ #define IDLE 0 #define DIAL 1 #define ALERTING 2 #define CONNECTED 3 #define BUSY 4 #define RINGING 5 /* Possible inputs */ #define ON_HOOK_IND 0 #define OFF_HOOK_IND 1 #define DIGITS_IND 2 #define CONNECTED_IND 3 #define INCOMING_CALL_IND 4 #define TIMEOUT_IND 5 #define PICKUP_IND 6

39 int transtab[][] = /* transtab[Input][CurrentState] => NextState */ { /* IDLE DIAL ALERTING CONNECTED BUSY RINGING */ { IDLE, IDLE, BUSY, IDLE, IDLE, IDLE }, /* ON_HOOK_IND */ { DIAL, DIAL, BUSY, IDLE, IDLE, IDLE }, /* OFF_HOOK_IND */ { IDLE, ALERTING, IDLE, IDLE, IDLE, IDLE }, /* DIGITS_IND */ { IDLE, DIAL, ALERTING, IDLE, IDLE, IDLE }, /* CONNECTED_IND */ { RINGING, DIAL, IDLE, CONNECTED, BUSY, RINGING }, /* INCOMING_CALL_IND */ { IDLE, DIAL, BUSY, IDLE, IDLE, IDLE }, /* TIMEOUT_IND */ { IDLE, DIAL, BUSY, IDLE, IDLE, CONNECTED }, /* PICKUP_IND */ }; curstate = transtab[event][curstate]; int curstate = IDLE;

40 Who defines state transitions ? May Define StateMachine

41 Who defines statemachine.. Context States Themselves State Tables

42 Guidelines Create A State Chart When Behavior Differs Based on State Place The Initial State In The Top-Left Corner Place The Final State In The Bottom-Right Corner State Names Should be Simple but Descriptive Question “Black Hole” States Question “Miracle” States Create a Hierarchy of State Charts for Very Complex Entities Name Transition Events in Past Tense

43 What Next Identify the implementation schemes Use XMI Aim for changes in statemachine which will need no or minimal changes to existing state implementations

44 Reference http://www.uml.org

45

46


Download ppt "UML Discussion on State Machines Perfectly static system is intensely uninteresting Because nothing ever happens."

Similar presentations


Ads by Google