1 / 45

UML

UML. Discussion on State Machines. Because nothing ever happens. Perfectly static system is intensely uninteresting. Real Systems. Dynamic in nature and always something is happening internally or externally. ATM Machine. Robot. Chemical Reaction. Network Router. Objects.

Download Presentation

UML

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. UML Discussion on State Machines

  2. Because nothing ever happens Perfectly static system is intensely uninteresting

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

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

  5. 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.

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

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

  8. Behavioral Elements

  9. Guard State Machine Transition State Event

  10. 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.

  11. Example Payment Authorization Authorizing Rejected Authorized Delivered

  12. 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”

  13. Validate Login/PIN

  14. Word Processing

  15. Brew Controller of coffee machine

  16. Coffee Machine Tank

  17. Sequential Sub states

  18. Concurrent Substates

  19. Food For Thought…. Identify States

  20. 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

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

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

  23. 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

  24. State Machine Concepts • Context • States • Transitions • A transition is a directed relationship between a source state and target state • Event

  25. Transition Source Trigger Guard Target Effects

  26. 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.

  27. State Machine Concepts • Context • States • Transitions • Event • An event is a specification of a type of observable occurrence

  28. Events • Call Event • Reception of request to synchronously invoke operation. • Creation of object • Deletion of object • Time Event • Models expiration of specific deadline.

  29. Events… • Signal Event • Reception of asynchronous signal

  30. Events… • Change Event • Implicit • Results as a change in some value of object attribute

  31. 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

  32. /* 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

  33. 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 */ }; int curstate = IDLE; curstate = transtab[event][curstate];

  34. Who defines state transitions ? MayDefineStateMachine

  35. Who defines statemachine.. • Context • States Themselves • State Tables

  36. 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

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

  38. Reference • http://www.uml.org

  39. Thank You

More Related