State Transition Diagram
State Transition Diagram
Example printer
Consider a printer is switched on Command is given to the printer to print a document If there are no papers loaded in the printer, it will give a signal which will compel the computer to display a message to load paper If the printer is jammed, it will refuse to print, even if paper is loaded in the printer, till the problem is resolved If the printer is fine and paper is loaded properly, then the printouts can be taken without any problem
Example : CD Player
Insert CD
Ready state Eject CD
Power switch on
Press Play button Press stop button
Playing state
Stat Machine
A state machine is a graph of states and transitions Usually a state machine is attached to a class and it describes the response of object of the class to event it receives. The object is examined in an isolated manner How the object responds to an event depends on the current state of the object One starting point shown by filled circle Several end points shown bulls eye symbol A state is shown by rectangle with rounded corners Arrow between states shows the transition of object from one state to another states
Events
A noteworthy occurrence which has consequences is called an event Types
Time event Guard condition becoming true event Change event Call event Signal event
Time event
Time is calculated as absolute time or the passage of relative amount of time eg. Antivirus software to run at 1.00pm daily.
State non scanned, under scanning
Change Event
Change event is evaluated continuously till it becomes true. When it is true transition fires
Call event
Call event represents the dispatch of an operation, the event may trigger a state transition in a state machine.
Signal
A signal represents a named object that is dispatched (thrown) asynchronously by one object and then received (caught) by another. Exceptions are supported by all programming languages.
as send
You can use a dependency, stereotypes as send, to indicate that an operation sends a particular signal.
The sender dispatches the operation and then waits for the receiver.
Here the sender is put in lock step with the flow of control of the receiver until the activity of the operation is carried out.
During Design:
We capture dynamic behavior of the individual classes or collection of collaboration classes
State
State of an Object represents the cumulative results of its behavior Transition
Progression from one state to another and will be triggered by event Event may be external or internal
Eg. Telephone
1. Telephone first installed Idle State (No previous behavior is of great interest, the phone is ready to initiate or receive calls) 2. Phone is off-hook Dialing state (Someone picks of the hand-set , Phone is not expected to ring, we expect to initiate conversation on to another phone)
3. Phone is on-hook Receiving state (if it rings we are expected to converse with the initiating phone)
State
Simple state
A state that has no sub states
Closed
locked
Unlocked
Locked
Depart
Begin Wash
Begin Wash
Reverse
Push F
Push N
Forward
up shift up shift up shift up shift
First
Down shift
Second
Down shift
Third
Down shift
Fourth
Down shift
Fifth
Forward state is sequential composite state showing First, second, Third, fourth. Substate: A state nested in another state is called substate
An Event is the specification of a significant occurrence that has a location in time and space. In the context of state machines, an event is an occurrence of a stimulus that can trigger a state transition. A signal is a kind of event that represents the specification of an asynchronous stimulus communicated between instances.
send event)
Customer at ATM
Authentication
Withdraw
Check PIN [incorrect] / incrementErrorCounter Check PIN [incorrect and ErrCounter >=Limit] /authentication Failed Rejection
Example
Event State Transition
digit (n)
digit (n)
dial tone
on-hook off-hook
dialling
on-hook
idle
Activities
Activities ultimately result in some action, which is made up of executable atomic computations that result in a change in state of the model or a return of a value The state of an object is a condition or situation during the life of an object during which it satisfies some condition, performs some activity, or waits for some event
Use Cases and scenarios provide a way to describe system behavior; that is, the interaction between objects in the system. Sometimes it is necessary to look at the behavior inside an object. A state chart diagram shows the states of a single object, the events or messages that cause a transition from one state to another, and the actions that result from a state change A state chart diagram will not be created for every class in the system, only for classes with significant" dynamic behavior.
States
A state is a condition during the life of an object during which it satisfies some condition, performs some action, or waits for an event. The state of an object may be characterized by the value of one or more of the attributes of the class. The Heater in a home might be in any of four states: Idle, Activating, Active, and ShuttingDown For example, a CourseOffering object may be open (able to add a student) or closed (maximum number of students already assigned to the CourseOffering object).
States
A state has several parts: 1. Name 2. Entry/exit actions 3. Internal transitions 4. Sub states 5. Deferred events: a list of events not handled in that state, but are postponed and queued for handling by the object in another state ( Message option during conversation in mobile phone)
Example
Objects in CourseOffering class can be in one of the following states:
Initialization (created prior to registration but students have not been added to it), Open (able to accept students), Closed (maximum number of students already registered for it), Canceled (no longer offered).
State Details actions that accompany all state transitions into a state may be placed as an entry action within the state. Likewise, actions that accompany all state transitions out of a state may be placed as exit actions within the state. Behavior that occurs within the state is called an activity. An activity starts when the state is entered and either completes or is interrupted by an outgoing state transition. As with actions and guards, this behavior typically is mapped to operations on the object
State transition
Represents a change from an originating state to a successor state (which may be the same as the originating state). An action can accompany a state transition. There are two ways to transition out of a state
automatic and nonautomatic.
Special States
There are two special states that are added to the state
chart diagram. The first is a start state. Each diagram must have one