0% found this document useful (0 votes)
4 views

Machine State Diagrams

The document outlines the design elements of an Online Library Management System, including Use Case Diagrams, Context Data Flow Diagrams (DFD), Entity-Relationship Diagrams (ERD), and State Diagrams. It details the interactions between members and librarians, the system's functions, and the dynamic behavior of components through state transitions. Additionally, it explains the purpose and application of State Machine Diagrams in modeling system behavior and differentiating between state changes and flowcharts.

Uploaded by

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

Machine State Diagrams

The document outlines the design elements of an Online Library Management System, including Use Case Diagrams, Context Data Flow Diagrams (DFD), Entity-Relationship Diagrams (ERD), and State Diagrams. It details the interactions between members and librarians, the system's functions, and the dynamic behavior of components through state transitions. Additionally, it explains the purpose and application of State Machine Diagrams in modeling system behavior and differentiating between state changes and flowcharts.

Uploaded by

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

Use Case Diagram, Context Data Flow Diagram (DFD), and Entity-Relationship

Diagram (ERD) and State Diagrams

Scenario: Online Library Management System

A library allows members to borrow and return books online. Members can search the
catalog, place holds on books, and view their borrowing history. The librarian manages the
inventory and checks book return statuses. The system also sends email reminders for due
dates.

1. Use Case Diagram

Actors:

 Member: Searches catalog, places holds, views borrowing history.


 Librarian: Manages inventory, checks return status.
 System: Sends reminders.

Use Cases:

 Search Catalog
 Borrow Book
 Return Book
 Place Hold
 View History
 Manage Inventory
 Send Reminders

2. Context DFD (Level 0)

Shows the system as a single process interacting with external entities.

External Entities:

 Members
 Librarians
 Email System

Data Flows:

 Requests and Responses (Search, Borrow, Return, etc.)


 Notifications (Reminders)
3. Entity-Relationship Diagram (ERD)

Key Entities:

 Member: Attributes include Member_ID, Name, Email.


 Book: Attributes include Book_ID, Title, Author, ISBN.
 Borrowing_Record: Tracks borrowing details.
 Inventory: Tracks availability and stock.

Relationships:

 Member borrows Books.


 Borrowing_Record tracks the due date and status.

STATE DIAGRAMS

The name of the diagram itself clarifies the purpose of the diagram and other details. It
describes different states of a component in a system. The states are specific to a
component/object of a system.

A Statechart diagram describes a state machine. State machine can be defined as a machine
which defines different states of an object and these states are controlled by external or
internal events.

Activity diagram explained in the next chapter, is a special kind of a Statechart diagram. As
Statechart diagram defines the states, it is used to model the lifetime of an object.

Purpose of Statechart Diagrams

Statechart diagram is one of the five UML diagrams used to model the dynamic nature of a
system. They define different states of an object during its lifetime and these states are
changed by events. Statechart diagrams are useful to model the reactive systems. Reactive
systems can be defined as a system that responds to external or internal events.

Statechart diagram describes the flow of control from one state to another state. States are
defined as a condition in which an object exists and it changes when some event is triggered.
The most important purpose of Statechart diagram is to model lifetime of an object from
creation to termination.

Statechart diagrams are also used for forward and reverse engineering of a system. However,
the main purpose is to model the reactive system.

Following are the main purposes of using Statechart diagrams −


 To model the dynamic aspect of a system.
 To model the life time of a reactive system.
 To describe different states of an object during its life time.
 Define a state machine to model the states of an object.

How to Draw a Statechart Diagram?

Statechart diagram is used to describe the states of different objects in its life cycle. Emphasis
is placed on the state changes upon some internal or external events. These states of objects
are important to analyze and implement them accurately.

Statechart diagrams are very important for describing the states. States can be identified as
the condition of objects when a particular event occurs.

Before drawing a Statechart diagram we should clarify the following points −

 Identify the important objects to be analyzed.


 Identify the states.
 Identify the events.

Following is an example of a Statechart diagram where the state of Order object is analyzed

The first state is an idle state from where the process starts. The next states are arrived for
events like send request, confirm request, and dispatch order. These events are responsible for
the state changes of order object.

During the life cycle of an object (here order object) it goes through the following states and
there may be some abnormal exits. This abnormal exit may occur due to some problem in the
system. When the entire life cycle is complete, it is considered as a complete transaction as
shown in the following figure. The initial and final state of an object is also shown in the
following figure.
Where to Use Statechart Diagrams?

From the above discussion, we can define the practical applications of a Statechart diagram.
Statechart diagrams are used to model the dynamic aspect of a system like other four
diagrams discussed in this tutorial. However, it has some distinguishing characteristics for
modeling the dynamic nature.

Statechart diagram defines the states of a component and these state changes are dynamic in
nature. Its specific purpose is to define the state changes triggered by events. Events are
internal or external factors influencing the system.

Statechart diagrams are used to model the states and also the events operating on the system.
When implementing a system, it is very important to clarify different states of an object
during its life time and Statechart diagrams are used for this purpose. When these states and
events are identified, they are used to model it and these models are used during the
implementation of the system.

If we look into the practical implementation of Statechart diagram, then it is mainly used to
analyze the object states influenced by events. This analysis is helpful to understand the
system behavior during its execution.
Notation of a State Machine Diagram

Following are the notations of a state machine diagram enlisted below:

1. Initial state: It defines the initial state (beginning) of a system, and it is represented
by a black filled circle.
2. Final state: It represents the final state (end) of a system. It is denoted by a filled
circle present within a circle.
3. Decision box: It is of diamond shape that represents the decisions to be made on the
basis of an evaluated guard.
4. 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.
5. 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.

What is a State Machine Diagram?


A state diagram is a uml diagram which 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 Machine diagrams are also known as State Diagrams and State-Chart Diagrams.
These both terms can be used interchangeably.
 A state machine diagram is used to model the dynamic behavior of a class in response
to time and changing external stimuli ( events that causes system to changes its state
from one to another).
 We can say that each and every class has a state but we don’t model every class using
State Machine diagrams.
Example:

The State Machine Diagram above shows the different states in which the verification sub-
system or class exist for a particular system.
Basic components and notations of a State Machine diagram
Below are the basic components and their notations of a State Machine Diagram:
1. Initial state
We use a black filled circle represent the initial state of a System or a Class.

2. Transition
We use a solid arrow to represent the transition or change of control from one state to
another. The arrow is labelled with the event which causes the change in state.

3. State
We use a rounded rectangle to represent a state. A state represents the conditions or
circumstances of an object of a class at an instant of time.
Final State
We use a filled circle within a circle notation to represent the final state in a state machine
diagram

Step1. Identify the System:


 Understand what your diagram is representing.
 Whether it’s a machine, a process, or any object, know what different situations or
conditions it might go through.
Step2. Identify Initial and Final States:
 Figure out where your system starts (initial state) and where it ends (final state).
 These are like the beginning and the end points of your system’s journey.
Step3. Identify Possible States:
 Think about all the different situations your system can be in.
 These are like the various phases or conditions it experiences.
 Use boundary values to guide you in defining these states.
Step4. Label Triggering Events:
 Understand what causes your system to move from one state to another.
 These causes or conditions are the events.
 Label each transition with what makes it happen.
Step5. Draw the Diagram with appropriate notations:
 Now, take all this information and draw it out.
 Use rectangles for states, arrows for transitions, and circles or rounded rectangles for
initial and final states.
 Be sure to connect everything in a way that makes sense.
Let’s understand State Machine diagram with the help of an example, ie for an online
order :

The UML diagrams we draw depend on the system we aim to represent. Here is just an
example of how an online ordering system might look like :
 On the event of an order being received, we transit from our initial state to Unprocessed
order state.
 The unprocessed order is then checked.
 If the order is rejected, we transit to the Rejected Order state.
 If the order is accepted and we have the items available we transit to the fulfilled order
state.
 However if the items are not available we transit to the Pending Order state.
 After the order is fulfilled, we transit to the final state. In this example, we merge the
two states i.e. Fulfilled order and Rejected order into one final state.
Note: Here we could have also treated fulfilled order and rejected order as final states
separately.
Applications of State Machine Diagram
Below are the main use cases of state machine diagram:
 State Machine Diagrams are very useful for modeling and visualizing the dynamic
behavior of a system.
 They are also used in UI design where they help to illustrate how the interface changes
in response to user actions, helping designers to create a better use experience.
 In game design, state machine diagrams can help model the behavior of characters or
objects, detailing how they change states based on player interactions or game events
 In embedded systems, where hardware interacts with software to perform tasks, State
Machine Diagrams are valuable for representing the control logic and behavior of the
system.
What are the Differences between a State Machine Diagram and a Flowchart?
Before understanding the differences between a state machine diagram and a flowchart,
firstly understand what is a flowchart:
What is a Flowchart?
An algorithm is like a set of clear instructions to solve a problem, and a flowchart is a
picture that shows those instructions.
 When we’re writing computer programs, a flowchart helps us map out the steps of the
algorithm to solve the problem.
 Non programmers use Flow charts to model workflows.
 We can call a flowchart a primitive version of an activity diagram.
 Business processes where decision making is involved is expressed using a flow chart.
Example:
A manufacturer uses a flow chart to explain and illustrate how a particular product is
manufactured.
State Machine Diagram vs. Flow Chart?
Below are the main differences between a state machine diagram and a flowchart:
State Machine Diagram Flow Chart

An State Machine Diagram is associated


A Flow Chart is associated with the
with the UML(Unified Modelling
programming.
Language)

The basic purpose of a state machine A flowchart on the other hand portrays the
diagram is to portray various changes in processes or commands that on execution
state of the class and not the processes or change the state of class or an object of
State Machine Diagram Flow Chart

commands causing the changes. the class.

Often used for processes, procedures, or


Primarily used for systems, emphasizing
algorithms involving actions and
their states and transitions.
decisions.

Conclusion
State Machine Diagrams in UML are like pictures that tell us how things change in a
system. They show the different situations a system can be in and how it moves between
them. These diagrams help us understand what events make these changes happen. Whether
it’s for designing software or explaining how something works, State Machine Diagrams
are like visual guides that make it easier to see and understand how a system behaves in
different situations.

You might also like