100% found this document useful (1 vote)
272 views

State Chart Diagram

The document discusses state chart diagrams, which are used to model the dynamic behavior of a system or class in response to external stimuli over time. A state chart diagram visually depicts the different states an object transitions between, the events that trigger transitions, and any actions that occur during transitions. It specifically shows states as rectangles, transitions as arrows between states, events that trigger transitions as labels on the arrows, and can include other elements like composite states, substates, initial and final end states. The document provides examples of when and how to use state chart diagrams, including for modeling reactive systems and depicting state changes in response to events.

Uploaded by

Saarth Shetty
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
272 views

State Chart Diagram

The document discusses state chart diagrams, which are used to model the dynamic behavior of a system or class in response to external stimuli over time. A state chart diagram visually depicts the different states an object transitions between, the events that trigger transitions, and any actions that occur during transitions. It specifically shows states as rectangles, transitions as arrows between states, events that trigger transitions as labels on the arrows, and can include other elements like composite states, substates, initial and final end states. The document provides examples of when and how to use state chart diagrams, including for modeling reactive systems and depicting state changes in response to events.

Uploaded by

Saarth Shetty
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

State chart diagram

A state diagram is used to represent the condition of the system or part of the system at finite
instances of time. It’s a behavioral diagram and it represents the behavior using finite state
transitions. State diagrams are also referred to as State machines and State-chart Diagrams.
These terms are often used interchangeably. So simply, a state diagram is used to model the
dynamic behavior of a class in response to time and changing external stimuli. We can say that
each and every class has a state but we don’t model every class using State diagrams. We
prefer to model the states with three or more states.

Uses of statechart diagram –


 We use it to state the events responsible for change in state (we do not show what
processes cause those events).
 We use it to model the dynamic behavior of the system .
 To understand the reaction of objects/classes to internal or external stimuli.

Firstly let us understand what are Behavior diagrams? There are two types of diagrams in
UML :
1. Structure Diagrams – Used to model the static structure of a system, for example- class
diagram, package diagram, object diagram, deployment diagram etc.
2. Behavior diagram – Used to model the dynamic change in the system over time. They are
used to model and construct the functionality of a system. So, a behavior diagram simply
guides us through the functionality of the system using Use case diagrams, Interaction
diagrams, Activity diagrams and State diagrams.

Difference between state diagram and flowchart –


The basic purpose of a state diagram is to portray various changes in state of the class and
not the processes or commands causing the changes. However, a flowchart on the other hand
portrays the processes or commands that on execution change the state of class or an object
of the class.

A statechart diagram shows a state machine, focusing on the flow of control from state to state. A
state machine is a behavior that specifies the sequences of states an object goes through during its
lifetime in response to events, together with its responses to those events. What distinguishes a state
chart diagram from other diagrams is its content. 

State chart diagrams commonly contain:

 Simple states and composite states


 Transitions including events and actions

When we model the dynamic aspects of a system, a class or a use case, we will use statechart
diagrams to model reactive (event-driven) objects.

Notation of a State Machine Diagram


Following are the notations of a state machine diagram enlisted below:
a. Initial state: It defines the initial state (beginning) of a system, and it is represented by a black
filled circle.
b. Final state: It represents the final state (end) of a system. It is denoted by a filled circle
present within a circle.
c. Decision box: It is of diamond shape that represents the decisions to be made on the basis of
an evaluated guard.
d. Transition: A change of control from one state to another due to the occurrence of some
event is termed as a transition. It is represented by an arrow labeled with an event due to
which the change has ensued.
e. State box: It depicts the conditions or circumstances of a particular object of a class at a
specific point of time. A rectangle with round corners is used to represent the state box.

Types of State
The UML consist of three states:

1. Simple state: It does not constitute any substructure.


2. Composite state: It consists of nested states (substates), such that it does not contain more
than one initial state and one final state. It can be nested to any level.
3. Submachine state: The submachine state is semantically identical to the composite state, but
it can be reused.
How to Draw a State Machine Diagram?
The state machine diagram is used to portray various states underwent by an object. The change in
one state to another is due to the occurrence of some event. All of the possible states of a particular
component must be identified before drawing a state machine diagram.

The primary focus of the state machine diagram is to depict the states of a system. These states are
essential while drawing a state transition diagram. The objects, states, and events due to which the
state transition occurs must be acknowledged before the implementation of a state machine diagram.

Following are the steps that are to be incorporated while drawing a state machine diagram:

1. A unique and understandable name should be assigned to the state transition that describes
the behavior of the system.
2. Out of multiple objects, only the essential objects are implemented.
3. A proper name should be given to the events and the transitions.

When to use a State Machine Diagram?


The state machine diagram implements the real-world models as well as the object-oriented systems.
It records the dynamic behavior of the system, which is used to differentiate between the dynamic and
static behavior of a system.

It portrays the changes underwent by an object from the start to the end. It basically envisions how
triggering an event can cause a change within the system.

State machine diagram is used for:

1. For modeling the object states of a system.


2. For modeling the reactive system as it consists of reactive objects.
3. For pinpointing the events responsible for state transitions.
4. For implementing forward and reverse engineering.

Example of a State Machine Diagram


An example of a top-level state machine diagram showing Bank Automated Teller Machine (ATM) is
given below.

Initially, the ATM is turned off. After the power supply is turned on, the ATM starts performing the
startup action and enters into the Self Test state. If the test fails, the ATM will enter into the Out
Of Service state, or it will undergo a triggerless transition to the Idle state. This is the state where
the customer waits for the interaction. 

Whenever the customer inserts the bank or credit card in the ATM's card reader, the ATM state
changes from Idle to Serving Customer, the entry action readCard is performed after entering
into Serving Customer state. Since the customer can cancel the transaction at any instant, so the
transition from Serving Customer state back to the Idle state could be triggered by cancel event.
Here the Serving Customer is a composite state with sequential substates that are Customer
Authentication, Selecting Transaction, and Transaction.

Customer Authentication and Transaction are the composite states itself is displayed by a hidden


decomposition indication icon. After the transaction is finished, the Serving Customer encompasses a
triggerless transition back to the Idle state. On leaving the state, it undergoes the exit
action ejectCard that discharges the customer card.
State diagram symbols and components
You can include many different shapes in a state diagram, particularly if you
choose to combine it with another diagram. This list summarizes the most
common shapes you may encounter.

Composite state

A state that has substates nested into it. See the university state
diagram example below. “Enrollment” is the composite state in this example
because it encompasses various substates in the enrollment process.

Choice pseudostate

A diamond symbol that indicates a dynamic condition with branched potential


results.

Event

An instance that triggers a transition, labeled above the applicable transition


arrow. In this case, “classes end” is the event that triggers the end of the “Being
taught” state and the beginning of the “Final exams” state.

Exit point

The point at which an object escapes the composite state or state machine,
denoted by a circle with an X through it. The exit point is typically used if the
process is not completed but has to be escaped for some error or other issue.
First state

A marker for the first state in the process, shown by a dark circle with a transition
arrow.

Guard

A Boolean condition that allows or stops a transition, written above the transition
arrow.

State

A rectangle with rounded corners that indicates the current nature of an object.

Substate

A state contained within a composite state's region. In the university state


machine diagram found below, “Open for enrollment” is a substate in the larger
“Enrollment” composite state.

Terminator

A circle with a dot in it that indicates that a process is terminated.

Transition

An arrow running from one state to another that indicates a changing state.
Transitional behavior

A behavior that results when a state transitions, written above the transition
arrow.

Trigger

A type of message that actively moves an object from state to state, written
above the transition arrow. In this example, “Issue with reservation” is the trigger
that would send the person to the airport travel agency instead of the next step in
the process.

State diagram examples


Calendar availability state diagram example

This state machine diagram example shows the process by which a person sets an
appointment on their calendar. In the “Check date” composite state, the system
checks the calendar for availability in a few different substates. If the time is not
available on the calendar, the process will be escaped. If the calendar shows
availability, however, the appointment will be added to the calendar.
University state diagram example

This state diagram shows the process of enrollment and classes at a university.
The composite state “Enrollment” is made up of various substates that will lead
students through the enrollment process. Once the student has enrolled, they will
proceed to “Being taught” and finally to “Final exams.”
Airport check-in state diagram example

The following example simplifies the steps required to check in at an airport. For
airlines, a state diagram can help to streamline processes and eliminate
unnecessary steps.

You might also like