0% found this document useful (0 votes)
17 views22 pages

05 State Chart Diagram

Uploaded by

MANYA MISHRA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views22 pages

05 State Chart Diagram

Uploaded by

MANYA MISHRA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

State Chart Diagram

State Chart Diagram


• Statechart diagrams are used to model how an object changes state.
• State is defined as a snapshot or a milestone of an object's behavior at a
particular point in time.
– For instance, the states of a computer can be defined as on, booting,
processing, idle, shutting down, and off.
– How a computer gets from the off state to the booting state or from
the processing state to the idle state is the job of statechart diagrams.
• Statechart diagrams depict how an individual object changes state when
its behavior is invoked.
• Statechart diagrams can also be used for a number of additional reasons.
– For instance, a statechart diagram can be used to show how screens change
state based upon user input.
– Statechart diagrams can also be used to show how a complex use case
progresses through its states.
State Chart Diagram
• A statechart diagram is composed of states, transitions, and events.
States : There are three separate notations:
• Basic State represents a point in the model that satisfies a condition.
– The basic state is shown as a rectangle with rounded corners. The name of the
state is placed within this rectangle.
• Start State
• End State

• A statechart diagram can include


zero or more start states.
• A statechart diagram can include
more than one end state, each
showing a distinct point in which
the model can terminate

Fig. Examples of State


Transitions: State Chart
Diagram
• Transitions show flow from
one state to another and is
modeled by an open arrow
from one state to another.

• In the example, It is possible to


start the car (putting it in the
Park state) and stop the car
without entering any other
possible state.
• It is not possible, however, to
enter the Drive 4 state without
entering the Drive 3 state.
Example: State Chart Diagram of an Order Management System
State Chart Diagram : Decision Point
• Decision Points are a convenience when modeling statechart diagrams,
because they make the diagram more visually appealing by grouping
transitions in a focal point away from the state from which they will go in
their own direction
State Chart Diagram : Synchronization
• Synchronization bars are used in a statechart diagram to show where
states need to catch up with or wait up for others. Synchronization bars
are used to show concurrent states

• A thick bar with one transition entering it indicates the beginning of a


synchronization period.
• Two or more transitions can exit the first synchronization bar on the other
side.
• All synchronization bars must be paired, so they must have a way to
combine back to one transition.
State Chart Diagram : Events
• Events are usually indicated
directly on the path of a transition
from a state to another state.
• They are used to indicate what
caused the state to change in a
model.
• In the example object has four
states: Clean, Dirty, Deleted, and
Saved.
• If the object was Clean, only Data
Entered can change the state and
it goes directly to Dirty.
• From here, either the Cancel or
the Continue event can change
the state again to either the
Deleted or the Saved state,
respectively.
State Chart Diagram : Actions
An action shows what behavior happens when an event occurs. There are five
basic action types that a state can initiate:
– Entry Used to specify the action that occurs when the state has been entered
– Exit Used to specify the action that occurs when the state is being abandoned
for another
– Do Used to specify the activity that occurs while the state is being occupied
– Include Invokes a submachine, represented by another statechart diagram
– Event Used to specify the action that occurs when a specific event is fired
• There are two notations for actions. The first is for the Entry, Exit, Do, and
Include action types:
action-label / action
• The following are examples of actions that use this notation:
entry / numberOfStudents = 0
exit / Classes->include(this)
do / refreshStudentList
include / performSomeSubtask
State Chart Diagram : Actions
In the example, when moving
from the Clean to the Dirty
state, the Data Entered event
fires the RecordData action,
which will most likely map to
an operation within the
modeled class.
Once in the Dirty state, if the
Cancel event is fired, the
EmptyData action is called.
If the Continue event is fired,
the SaveData action is called.
On exiting both the Deleted
and the Saved states, the Reset
action is called and the state is
restored to the Clean state.
Example: State Chart Diagram
• The following StateChart Diagram describes the Compiler Object in
some detail as a project is loaded
Example: State Chart Diagram
• Sometimes, objects can have hierarchical states.
• Hierarchical states are present in a diagram when a single state can have
additional substates that are unique to itself.
• Substates or states that are unique to a particular state of a diagram, can be
modeled using multiple statechart diagrams.

In this notation, the object can be in any one of the following sets of states:
• State A, State B and State 1 and State 2
In the left diagram, Event A is causing the state of the object to change from State A to State B.
In the right diagram, Event A is causing the object to move from the start state to either State 1
or State 2 depending upon Condition 1 or Condition 2.
Example: State Chart Diagram
• When a project is loaded, the object enters the Editing state.
• From there, the project can be unloaded to exit the statechart diagram, but it
can also be Run to enter the Running state.
• The Running state is further described in the second statechart diagram, and
the Run event is guarded that determine which transition is chosen.
• If the mode of the object is Debug, then the Debug state is chosen, thus
making the object in the Running and Debug states at the same time.
• Similarly, if the mode were equal to Release, then the Optimization Mode
state would also be active along with the Running state for the object.
State Chart Diagram: Composite State
• Another way to illustrate substates is by using the notation for composite
states.
• Composite states are modeled by creating a very large state and embedding
the substate statechart within it
State Chart Diagram: Composite State
Draw a flow char for the following description:
valid states (not including the start or end states) for the preceding location:
– Full Time Student
– Probationary Student and First Degree Probation
– Probationary Student and Second Degree Probation
– Expelled Student
• Once a student is added to the roster, the Full Time Student state is valid.
• A Probation event will make you a Probationary Student depending upon the
severity.
– From there, you can get a Reprieve event and go back to being a Full Time
Student.
– Full Time Student cannot get to Expelled Student without becoming a
Probationary Student, and a Probationary Student will become an Expelled
Student with a Probation event regardless of what the substate value is (First or
Second Degree Probation).
Composite State – Example - Solution
How to Model State Charts

• Identify the entities (objects or use cases) that need to be


further detailed.
• Identify the start and end states for each entity.
• Determine the events relating to each entity.
• Create the statechart diagram beginning with the start event.
• Create composite states where necessary.
Please note that these instructions mention multiple entities,
but keep in mind that a Statechart diagram represents a single
entity.
The instructions indicate that the steps need to be iterated for
each entity that is involved.
How to Model State Chart Diagram
(1) Identify the entities
• The first thing you need to do is identify which entities need to be further detailed
with statechart diagrams.
• Statechart diagrams should be drawn for complex entities but not necessarily for
entities with complex behavior.
• In this case, perhaps an activity diagram would be better suited to explain the
entity's complex behavior with other entities.
To identify the start states for an entity, you have to ask
• how the entity is instantiated.
• How does it come to life?
For Example: The Grade object is instantiated when we have a new grade to
save.
To identify the end states for an entity, you ask the opposite question: When is this
entity removed from the system?
• The answer for the Grade object is after it has completed its attempt to save
the data, regardless of its success.
Following are the start and end states for the Grade object's statechart diagram
depicting the save functionality:
i. Information Entered start state
ii. Destroy end state
How to Model State Chart Diagram
(2) Determine the Events relating to the entities
• Events ultimately become the functionality of an entity.
• To determine the events of an entity, you need to ask yourself what the
entity does.
– Looking at the Grade object, we can determine that it saves the grades.
– the Grade object accepts data, successfully saves data, and unsuccessfully
saves data
(remember, we are considering the task of saving a grade to be a complex task),
• With these events, we can create a list of states that these events will
bring us to for the Grade object:
Ready For when the data has been loaded
Persisting For when the data is being saved
Saved For when the data has been saved
Error For when the data has not been saved because of an error
How to Model State Chart Diagram
(3) Create the Statechart from the Start State

State Chart
for Grade
Object
How to Model State Chart Diagram
(4) Specify the Composite States Where Necessary
• In the example, we can
consider Persisting to
be very general
• we can give substates
that would include
either Load, Update
and Save, or simply
Insert.
Practice Example
• Consider the point-of-sale system and create a statechart diagram describing how
it accepts orders, processes them, and debits inventory upon success.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy