State Machine Diagram.

Slides:



Advertisements
Similar presentations
State Diagram 1. State diagram: Shows the behavior of one object. They describe all of the possible states that a particular object can get into and how.
Advertisements

UML State Machine Diagrams and Modeling
State Charts Mehran Najafi. Reactive Systems A reactive, event-driven, object is one whose behavior is best characterized by its response to events dispatched.
UML State chart/machine diagram State machine diagram is a behavior diagram which shows discrete behavior of a part of designed system through finite state.
Unified Modeling Language Unit 4. Dynamic Modeling.
Chapter 8: Modelling Interactions and Behaviour
Essentials of state and activity diagram Lecture 24.
State Machine Diagrams (State Chart in UML 1) Specifying Control (ref: Chapter 11 Bennett, Mc Robb and Farmer)
1 CS/CPE 426 Senior Projects Chapter 21: State Machines Chapter 22:Advanced State Machines [Arlow and Neustadt 2005] March 24, 2009.
State Change Modelling. Aim: To introduce the concept and techniques for describing the changes in state that may occur to an object in its lifetime.
Practical Object-Oriented Design with UML 2e Slide 1/1 ©The McGraw-Hill Companies, 2004 PRACTICAL OBJECT-ORIENTED DESIGN WITH UML 2e Chapter 10: Statecharts.
SE-565 Software System Requirements More UML Diagrams.
State and Sequence Diagrams Modelling dynamic information So far we have seen: Use Case Diagrams – requirements capture, interface.
State Machine Diagram Chapter 10. State Machine Diagram Used to describe system behavior.
Lecture 4 Finite State Machine CS6133 Software Specification and Verification.
Chapter 10 State Machine Diagrams
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 8: Modelling Interactions and Behaviour.
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 8: Modelling Interactions and Behaviour.
NJIT Modeling Behavior in State Chart Diagrams Chapter 29 Rafael Mello.
 2000 Deitel & Associates, Inc. All rights reserved. Optional Case Study - Chapter 3 Outline 3.1 Introduction 3.2 Class Attributes 3.3 Statechart Diagrams.
1 Modeling interactions and behavior Lecturer Dr. Mai Fadel.
Session 21 Applying the Basic Statechart to the Case Study Written by Thomas A. Pender Published by Wiley Publishing, Inc. October 27, 2011 Presented by.
UML -Part 3. Dynamic Diagram Types Interaction Diagrams - Set of objects or roles and the messages that can be passed among them. – Sequence Diagrams.
Activity diagrams. Introduction ● Activity diagrams are a behavioural model that represent the dynamics of the system. ● An activity diagram is essentially.
7 Systems Analysis and Design in a Changing World, Fifth Edition.
Information System Design IT60105
1 Kyung Hee University Statecharts Spring Kyung Hee University Specifying Objects’ Behaviour  Interaction diagrams show message-passing behaviour.
UML Discussion on State Machines Perfectly static system is intensely uninteresting Because nothing ever happens.
CSCI-383 Object-Oriented Programming & Design Lecture 12.
Chapter 11 Activity Diagrams. 2 “Activity diagrams are a technique to describe procedural logic, business processes, and work flows” - M. Fowler An activity.
Object Oriented Analysis & Design & UML (Unified Modeling Language)1 Part VI: Design Continuous Activity Diagams State Diagrams.
CS212: Object Oriented Analysis and Design Lecture 34: UML Activity and Collaboration diagram.
States.
CS3773 Software Engineering Lecture 06 UML State Machines.
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 26. Review UML behavioral Diagrams – Sequence diagram.
INFO 620Lecture #71 Information Systems Analysis and Design Design Class Diagrams and others INFO 620 Glenn Booker.
Practical Object-Oriented Design with UML 2e Slide 1/1 ©The McGraw-Hill Companies, 2004 PRACTICAL OBJECT-ORIENTED DESIGN WITH UML 2e Chapter 10: Statecharts.
State Machine Diagram Chapter 5 Introduction Pages
Practical Object-Oriented Design with UML 2e Slide 1/1 ©The McGraw-Hill Companies, 2004 PRACTICAL OBJECT-ORIENTED DESIGN WITH UML 2e Chapter 6: Restaurant.
® IBM Software Group © 2009 IBM Corporation Module 11: Creating State Machine Diagrams Essentials of Modeling with IBM Rational Software Architect V7.5.
UML Review: State Machines. Sept. 17, 2003Lecture 5: CS660 Fall Overview States Transitions Activities Modeling object lifeline Creating well-structured.
Chapter 1 Overview of UML for Java Programmers. 2 Outline Diagram Types Diagram Types Class Diagrams Class Diagrams Object Diagrams Object Diagrams Sequence.
© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1 Advanced UML State Diagrams.
Appendix 3 Object-Oriented Analysis and Design
Chapter 5 System modeling
State Machine Model.
State Machine Diagrams
Course Outcomes of Object Oriented Modeling Design (17630,C604)
Object-Oriented Analysis and Design
Standard UML: Communication and Dynamic Behavior
Activity Diagram.
Activity and State Transition Diagram
State Machine Diagrams
UML State Diagrams.
UML dynamic Modeling (Behavior Diagram)
UML Activity Diagrams & State Charts
States.
Object Oriented System Design
CS/CPE 426 Senior Projects
Activity Diagrams.
CIS 375 Bruce R. Maxim UM-Dearborn
CS/CPE 426 Senior Projects
Graph Coverage for Specifications CS 4501 / 6501 Software Testing
States.
CHAPTER 2 Object-Oriented Modeling Using UML (Continued)
CS 791Z State Machines & Advanced State Machines
CIS 375 Bruce R. Maxim UM-Dearborn
Behavioral Diagrams P. P. Mahale
Modeling Behavior in Statechart Diagrams
Presentation transcript:

State Machine Diagram

Introduction State chart diagram is used to visualize the reaction of a system by internal/external factors. Any real time system is expected to be reacted by some kind of internal/external events. These events are responsible for state change of the system. Statechart diagram is used to represent the event driven state change of a system. It basically describes the state change of a class, interface etc. It is a familiar technique to describe the behavior of a system. In OO approach, draw state machine diagram for a single class to show the lifetime behavior of a single object

Event Driven System The door can be in one of three states: "Opened", "Closed" or "Locked". It can respond to the events Open, Close, Lock and Unlock. Not all events are valid in all states; for example, if a door is opened, you cannot lock it until you close it.

Components of State Diagram States - A state is denoted by a round-cornered rectangle with the name of the state written inside it. Initial and Final States - The initial state is denoted by a filled black circle and may be labeled with a name. The final state is denoted by a circle with a dot inside and may also be labeled with a name.

Cond... Transitions - Transitions from one state to the next are denoted by lines with arrowheads. A transition may have a trigger, a guard and an effect, as below. "Trigger" is the cause of the transition, which could be a signal, an event, a change in some condition, or the passage of time. "Guard" is a condition which must be true in order for the trigger to cause the transition. "Effect" is an action which will be invoked directly on the object that owns the state machine as a result of the transition.

Cond... Self-Transitions - A state can have a transition that returns to itself. This is most useful when an effect is associated with the transition.

Example Scenario... I want to keep my valuables in a safe that's hard to find. So to reveal the lock to the safe, I have to remove a strategic candle from its holder, but this will reveal the lock only while the door is closed. Once I can see the lock, I can insert my key to open the safe. For extra safety, I make sure that I can open the safe only if I replace the candle first. If a thief neglects this precaution, I'll unleash a nasty monster to devour him.

Controller can be in three states: Wait, Lock, Open and have rules by which controller changes from state to state. These rules are in the form of transitions: the lines that connect the states. Transition indicates a movement from one state to another. Each transition has a label that comes in three parts: trigger-signature [guard]/activity The trigger-signature is an event that triggers a potential change of state. The guard is a Boolean condition that must be true for the transition to be taken. The activity is some behavior that's executed during the transition. It may be any behavioral expression.

Cond... All parts in transition are optional. The full form of a trigger-signature may include multiple events and parameters. A missing activity indicates that don't do anything during the transition. A missing guard indicates that always take the transition if the event occurs. A missing trigger-signature is rare but does occur. It indicates that take the transition immediately (called Activity states).

Cond... When an event occurs in a state, take only one transition out of it. So if you use multiple transitions with the same event then the guards must be mutually exclusive. Eg: Lock state If an event occurs and no transition is valid, then the event is ignored. Eg: a safe-closed event in the Wait state or a candle-removed event with the door closed. The final state indicates that the state machine is completed, implying the deletion of the controller object. Thus, if someone fall in trap, the controller object terminates. Eg: Final state need to put the rabbit in its cage and reboot the system.

Internal Activities States can react to events without transition, using internal activities: putting the event, guard, and activity inside the state box itself. An internal activity is similar to a self-transition: a transition that loops back to the same state.

Special activities Two special activities: the entry and exit activities. The entry activity is executed whenever you enter a state; The exit activity, whenever you leave. However, internal activities do not trigger the entry and exit activities; that is the difference between internal activities and self-transitions.

Activity States In states, the object is quiet and waiting for the next event before it does something. A special state called Activity state, in which the object is doing some ongoing work.

Activity States Cond... The ongoing activity is marked with the do/; hence the term do-activity. Once the search is completed, any transitions without an activity are taken. Eg: Display new hardware If the cancel event occurs during the activity, the do-activity is halted, and go back to the Update Hardware Window state. Both do-activities and regular activities carrying out some behavior. Regular activities occur "instantaneously" and cannot be interrupted by regular events, while do-activities can take finite time and can be interrupted. UML 1 used the term action for regular activities and used activity for do-activities.

Superstates with nested Substates Several states share common transitions and internal activities. Make them as substates and move the shared behavior into a superstate.

Concurrent States States can be broken into several orthogonal state diagrams that run concurrently. Eg: Consider a pathetically simple alarm clock that can play either CDs or the radio and show either the current time or the alarm time. The choices CD/radio and current/alarm time are orthogonal choices.

History pseudostate History state is used to remember the previous state of a state machine when it was interrupted. when the clock is switched on, the radio/CD choice goes back to the state, the clock was in when it was turned off. The arrow from the history pseudostate indicates what state to be in on the first time when there is no history.

Choice Pseudo-State A choice pseudo-state is shown as a diamond notation with one transition arriving and two or more transitions leaving.

Junction pseudo-states Used to chain together multiple transitions. A single junction can have one or more incoming, and one or more outgoing, transitions; a guard can be applied to each transition. Junctions are semantic-free. A junction which splits an incoming transition into multiple outgoing transitions realizes a static conditional branch, but in choice pseudo-state which realizes a dynamic conditional branch.

Terminate Pseudo-State Entering a terminate pseudo-state indicates that the lifeline of the state machine has ended. A terminate pseudo-state is notated as a big cross.

Implementing State Diagrams A state diagram can be implemented in three main ways: Nested switch State pattern State tables Nested switch-most direct approach to handling a state diagram. Although it's direct, it's long-winded, even for this simple case. For this approach, It is also very easy to get out of control.

Nested switch

Implementing State Diagrams Cond... State pattern creates a hierarchy of state classes to handle behavior of the states. Each state in the diagram has one state subclass. The controller has methods for each event, which simply forwards to the state class. The state pattern is easier to put together when you need it, and although it needs a new class for each state, it's a small amount of code to write in each case.

State pattern

Implementing State Diagrams Cond... State table approach captures the state diagram information as data in a table. We then build either an interpreter that uses the state table at runtime or a code generator that generates classes based on the state table. Obviously, the state table is more work to do once, but then you can use it every time you have a state problem to hold. A runtime state table can also be modified without recompilation.

State Table

When to Use State Diagrams? State diagrams are good at describing the behavior of an object across several use cases. State diagrams are not very good at describing behavior that involves a number of objects collaborating. Use state diagrams only for those classes that exhibit interesting behavior, where building the state diagram helps you understand what is going on.