State Diagram-S
State Diagram-S
State Diagram-S
This modeling technique came from a more formal area called automata theory.
State transition diagram depicted a Finite State Machine.
Software Program View
turnOn
turnOff
turnOff turnOff
on off
on off
2. Even with a modest number of states and events, the state transition
diagram, which really depicts the transition rules, can be enormous.
State Diagrams
• State diagrams are used to show possible states a
single object can get into
– shows states of an object
Tracking
entry action
entry / setMode(on Track)
exit action exit / setMode(off Track)
internal transition Tracking / tracker.Acquire()
newTarget/tracker.ChangeTrack()
external transition
do / followTarget
activity
getFirstItem
getNextItem Checking
[not all items checked]
do / checkItem
cancelled
itemsReceived
[some items not in stock]
cancelled
Waiting Delivered
cancelled
Cancelled
Types of State Machine Diagram
• Protocol state machine: Protocol state machines are primarily used to
model the behavior of an external entity or component with which a
system interacts. They define the sequences of messages or events
exchanged between the system and the external entity to achieve a
specific interaction or protocol. The focus of a protocol state machine
is on defining the order and conditions under which messages or
events are sent and received during an interaction.
• Behavioral state machine: Behavioral state machines, on the other
hand, are used to model the internal behavior of a single entity or
component within a system. They describe how an object or
component transitions between different states based on events or
conditions and how it responds to those events by executing actions.
Behavioral state machines focus on modeling the behavior of an entity
or component from an internal perspective.
Protocol state machine: login authentication protocol. In this scenario, a client needs to establish a
connection with a server and perform a login process following a predefined sequence of states and
messages
States:
• Transition 3: Connected -> Authenticating
• Disconnected: The initial state where the
client is not connected to the server. • Trigger: Client sends login credentials
(username and password).
• Connecting: The client initiates a connection
to the server. • Action: Client sends an "AUTHENTICATE"
message with credentials.
• Connected: The connection is established.
• Transition 4: Authenticating -> Authenticated
• Authenticating: The client sends login
credentials to the server. • Trigger: Server verifies credentials and
confirms authentication.
• Authenticated: The server verifies the
credentials and confirms successful • Action: Server sends an "AUTH_SUCCESS"
authentication. message.
• Error: If any error occurs during the process. • Transition 5: Authenticating -> Error
Transitions and Messages: • Trigger: Server rejects the login attempt.
• Transition 1: Disconnected -> Connecting • Action: Server sends an "AUTH_FAIL"
message.
• Trigger: Client initiates a connection request.
• Transition 6: Connected -> Error
• Action: Client sends a "CONNECT" message
to the server. • Trigger: Any unexpected error occurs.
• Transition 2: Connecting -> Connected • Action: Server sends an "ERROR" message
and terminates the connection.
• Trigger: Server acknowledges the connection.
• Action: Server sends an "ACK" message.
Behavioral state machine:A traffic light can have several states and transitions based on time intervals
and user input
States:
• Red Light: The initial state where the traffic
light displays a red signal to stop vehicles.
• Red-Yellow Light: A transitional state where
both the red and yellow lights are briefly
displayed to signal that the light is about to
change.
• Green Light: The state where the traffic light
displays a green signal to allow vehicles to
proceed.
• Yellow Light: A transitional state where the
yellow light is displayed to signal that the
light is about to change.
• Flashing Yellow Light: A state where the
yellow light flashes, indicating caution before
a green light.
Transitions and Actions: • Transition 4: Yellow Light -> Red Light
• Transition 1: Red Light -> Red-Yellow Light – Trigger: A predefined time interval for
– Trigger: A predefined time interval the yellow light has passed.
(e.g., 5 seconds) for the red light has – Action: Change the light to red,
passed. signaling vehicles to stop.
– Action: Begin displaying the red-yellow • Transition 5: Green Light -> Flashing Yellow
light for a brief period. Light
• Transition 2: Red-Yellow Light -> Green – Trigger: A button is pressed by a
Light pedestrian to request a pedestrian
– Trigger: A predefined time interval for crossing.
the red-yellow light has passed. – Action: Display a flashing yellow light,
– Action: Change the light to green, indicating that vehicles should be
allowing vehicles to proceed. cautious due to the pedestrian crossing
• Transition 3: Green Light -> Yellow Light request.
– Trigger: A predefined time interval • Transition 6: Flashing Yellow Light -> Red
(e.g., 20 seconds) for the green light has Light
passed. – Trigger: The pedestrian has crossed or
– Action: Begin displaying the yellow the request is canceled.
light, indicating that the green light will – Action: Change the light to red to stop
change soon. vehicles.
Advanced State Machine Modeling
• Nested states
• Concurrent states
Nested State Machine- Telephone
Nested State Machine- Printer
• A Printer object cycles between two separate paths. The two independent
paths are;
➢ Representing states of the work cycle.
➢ Representing states of the input paper tray
Concurrent State Machine- Printer
State Diagrams Importants
DigitalWatch
A
Set hours
do / show hours A
A
Display time Set minutes
B / advance hour
do / show hours and do / show minutes
minutes
B / advance minute
• Design an Appointment Management System (AMS) for a hospital to
efficiently handle patient appointments. The system should allow
patients to request appointments, doctors to accept or decline requests,
and receptionists to schedule confirmed appointments. It should also
handle appointment cancellations and rescheduling while ensuring that
overbooking is prevented.
Difference between Activity and State Chart
Diagram
State diagram shows the object undergoing a process. It gives a clear
picture of the changes in the object's state in this process.
e.g: ATM withdraw
Card object state: Checking, Approving, Rejecting
Activity diagram is a fancy flow chart which shows the flow of activity of
a process.