State Machine Diagram
State Machine Diagram
State Machine Diagram
Machine
Diagram
CSE347 – Information System
Analysis and Design
Instructor
Dr. Shamim H Ripon
Dr. Shamim H Ripon, EWU 2
Behavioral UML diagrams
• Behavioral UML diagrams focus on illustrating the dynamic aspects of a software
system, showcasing how it behaves, responds to stimuli, and undergoes state
changes during runtime.
• During analysis, behavioral models describe what the internal logic of the
processes is without specifying how the processes are to be implemented. Later,
in the design and implementation phases, the detailed design of the operations
contained in the object is fully specified.
• During analysis, analysts use behavioral models to capture a basic understanding
of the dynamic aspects of the underlying business process. Traditionally,
behavioral models have been used primarily during design, where analysts refine
the behavioral models to include implementation details.
• The behavioral diagrams are categorized as follows:
• use case diagrams,
• interaction diagrams,
• state–chart diagrams, and
• activity diagrams.
Dr. Shamim H Ripon, EWU 3
Behavioral state machine
• A behavioral state machine is a dynamic model that shows the different
states through which a single object passes during its life in response to
events, along with its responses and actions.
• Typically, behavioral state machines are not used for all objects; rather,
behavioral state machines are used with complex objects to further defi ne
them and to help simplify the design of algorithms for their methods.
• The behavioral state machine shows the different states of the object and
what events cause the object to change from one state to another.
• Behavioral state machines should be used to help understand the dynamic
aspects of a single class and how its instances evolve over time.
A behavioral state machine representing the patient class in the context of a hospital environment. From
this diagram we can tell that a patient enters a hospital and is admitted after checking in. If a doctor finds
the patient to be healthy, he or she is released and is no longer considered a patient after two weeks
elapses. If a patient is found to be unhealthy, he or she remains under observation until the diagnosis
changes.
Dr. Shamim H Ripon, EWU 7
State Guard
Frame Initial state Event Transition condition Final state
• An event is something that takes place at a certain point in time and changes a value or values that
describe an object, which, in turn, changes the object’s state. It can be a designated condition
becoming true, the receipt of the call for a method by an object, or the passage of a designated period
of time. The state of the object determines exactly what the response will be.
• A transition is a relationship that represents the movement of an object from one state to another
state. Some transitions have a guard condition.
• A guard condition is a Boolean expression that includes attribute values, which allows a transition to
occur only if the condition is true. An object typically moves from one state to another based on the
outcome of an action triggered by an event.
• An action is an atomic, non-decomposable process that cannot be interrupted. From a practical
perspective, actions take zero time, and they are associated with a transition. In contrast, an activity is
a nonatomic, decomposable process that can be interrupted. Activities take a long period of time to
complete, and they can be started and stopped by an action.
• "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.
Dr. Shamim H Ripon, EWU 14
• State Actions - In the transition example above, an effect was associated with the transition. If
the target state had many transitions arriving at it, and each transition had the same effect
associated with it, it would be better to associate the effect with the target state rather than the
transitions. This can be done by defining an entry action for the state. The diagram below
shows a state with an entry action and an exit action.
• It is also possible to define actions that occur on events, or actions that always occur. It is
possible to define any number of actions of each type.
Alternative way to
show the same
•The ∞ symbol indicates that details of the Check PIN
information
sub-machine areDr.shown
Shamim in a separate
H Ripon, EWU diagram. 16
• Entry Point - Sometimes you won’t want to enter a sub-machine at the normal initial state.
For example, in the following sub-machine it would be normal to begin in the "Initializing"
state, but if for some reason it wasn’t necessary to perform the initialization, it would be
possible to begin in the "Ready" state by transitioning to the named entry point.
• Exit Point - In a similar manner to entry points, it is possible to have named alternative exit
points. The following diagram gives an example where the state executed after the main
processing state depends on which route is used to transition out of the state.
Dr. Shamim H Ripon, EWU 17
• Choice Pseudo-State - A choice pseudo-state is shown as a diamond with one transition
arriving and two or more transitions leaving. The following diagram shows that whichever
state is arrived at, after the choice pseudo-state, is dependent on the message format
selected during execution of the previous state.
• History States - A history state is used to remember the previous state of a state
machine when it was interrupted. The following diagram illustrates the use of history
states. The example is a state machine belonging to a washing machine.
• Draw the initial state in the top left corner of the diagram.
• Draw the final state in the bottom right corner of the diagram.
2. Identify Object Th e second step is to identify the various states that an object will have over its lifetime. This
States includes establishing the boundaries of the existence of an object by identifying the initial
and final states of an object. We also must identify the states of an object
3. Lay Out The third step is to determine the sequence of the states that an object will pass through
Diagram during
its lifetime.
4. Add The fourth step is to identify the transitions between the states of the objects and to add the
Transitions events, actions, and guard conditions associated with the transitions. The events are the
triggers
that cause an object to move from one state to the next state.
5. The fifth step is to validate the behavioral state machine by making sure that each state is
Validate reachable and that it is possible to leave all states except for final states.
Dr. Shamim H Ripon, EWU 23