SlideShare a Scribd company logo
3
Most read
10
Most read
21
Most read
UNIT 4: UNDERSTANDING
COMMUNICATIONS VIA
NETWORK AND WEB
State Machine
A state machine
• A state machine defines an application process flow at runtime.
When you activate the application, the process flow is converted to a
state machine.
• A state machine main purpose is reading a series of inputs and
switching to different states after reading a new input.
Example: State machine
• Fetching data from an endpoint.
• The program can have 3 states: loading, success, and error.
• A state machine also has a starting state, which
coincidentally here is named “not started” but you can
name it anything you want.
• Here, the starting state indicates that the API is not called
yet.
• When a user opens a screen, the screen begins fetching
the data, so the state moves to “loading”.
• If the API call returns success/error, the state moves to
SUCCESS/ERROR respectively.
• After that, if the user refreshes the screen, the state goes
back to LOADING.
• We could call the annotation “fetch”, “error”, “success”,
“refresh” an event or input.
• The transition function receives the current state and an
input and determines the next state.
Example: State machine of a Washer Dryer
• We want this machine to have 4 distinct states that we go from one to
the next in this sequence:
1. Initial State – Where we are when we are waiting to start the wash
2. Wash – Where we wash with soap and water
3. Dry – Where we dry the clothes
4. Done
State Diagram for Washer-Dryer Machine
State Diagram for Washer-Dryer Machine…
1. We start at an “Initial” state whenever we start up the machine
• Let’s also assume this stage is when you’d put in the soap and clothes
• Once input “Coin is in” is 1, GTNS is now
• This event triggers leaving the current state to go to the next state
State Diagram for Washer-Dryer Machine…
2. This is followed by the next state, “Wash”
• “Coin inserted” is now 0 at this point (so GTNS goes back to 0)
• While soap is still present, GTNS goes back to 0 – When the input “Soap is no
longer present” goes to 1, GTNS goes to 1
• This event triggers leaving the current state to go to the next state
State Diagram for Washer-Dryer Machine…
3. This is followed by the next state, “Dry”
• This new state sets an output that triggers a timer
• The input “Soap is no longer present” goes to 0, so GTNS is 0 also
• While the input “Clothes are now dry” is 0 , GTNS remains at 0 too
• When the input “Clothes are now dry” is 1, GTNS changes to 1
• This event triggers leaving the current state to go to the next state
4. This is followed by the next and last state, “Done”
• When you’re here, you go back to the “initial” state
• No inputs to consider: you do move this regardless
Components of a State Machine
• A state machine consists of the following components:
• State: basically a status of the machine. While being in a state, a machine
waits for the event that will trigger a transition to a different state.
• Event: the actual inputs that the machine reads. If we speak about a mobile
application as an example, an event would be an action performed by the
user.
• Transition: the movement of the machine from one state to another after a
certain event occurs.
States of a state machine
• States are elements of a state-machine system.
• An application usually has many states, and can include different
types of states.
• Each state has a previous state and a following state, unless it is the
initial state or the final state.
• There can be only one initial state, but, depending on user
interaction, there can be many final states.
initial state
• An initial state is the first state in
an application, and only handles
state transitions to follow-up
states, based on transition rules.
• The initial-state is Start Application,
which is created automatically
when you create an application,
and cannot be deleted.
• By default, the name of the initial
state is the same as the name of
the application.
Finite State Machine/Synchronous state
machine
• A finite state machine is an abstract machine that can be in exactly
one of a finite number of states at any given time.
• Finite State Machine is a state machine, with a finite number of
states.
• It can be in one state at a time, and can transition to a different state once
something happens.
• A finite state machine must have:
• an initial state which provides a starting point, and
• a current state which remembers the product of the last state transition.
Example: Finite State Machine
Figure: state diagram
Class Activity
• Write a state transition table for the state machine diagram below
Class Activity
• Write a state transition table for the state machine diagram below
Two types/models of FSM
• Moore machine: its output is a function of present state only
• Mealy machine: its output is a function of present state and present
input
its output is a function of present state only
its output is a function of present state and present
input
Comparison of Mealy and Moore FSM
Building a state machine for Android app
• Step 1: Define the states
• Step 2: Define the actions
• Step 3: Connect the events with actions
• Step 4: Write a bit of code
• Step 5: Implement the states and build the activity
• Example:
• EventList+ AddEventClicked = AddEvent
• AddEvent + EventSelected = NameEvent
• NameEvent+ SubmitEventClicked = EventList
The benefits of using state machine pattern in
your mobile application
• Allows developers to focus only on the configuration of states and transitions
without digging into the “how” aspect of the process.
• once a developer configures the needed states and the conditions for the transitions, the
work is done and the machine will function in accordance with the set conditions.
• Ensures a high level of predictability and eliminates the possibility of any malfunctions since
every action is predefined.
• It allows developers to visualize the work and makes the whole system more transparent.
• Elimination of hard coding conditions in the code
• Easy tracking of the processes due to the finite number of states and machine’s
predictability
• An option to isolate certain pieces of code due to the independency of every
action
• High stability of the system.
Disadvantages of using state machine pattern
in your mobile application
• Not very suitable for asynchronous execution
• Possibility to have complex code if several transitions are executed
from one state
• Limited support from the community
• Tricky data management and storage
• A possibility to obtain your own persistence layer in order to load
balance properly
You can look at feather explanation on state machine

More Related Content

What's hot (20)

PPTX
Data Structure and Algorithms.pptx
Syed Zaid Irshad
 
PPTX
Expert System (Forward and Backward Chaining)
Sohail Ahmed
 
PPTX
C++ Class & object pointer in c++ programming language
HariTharshiniBscIT1
 
PPTX
Access modifiers in java
Madishetty Prathibha
 
PDF
C- Programming Assignment 3
Animesh Chaturvedi
 
PDF
chapter-7-classes-and-objects.pdf
study material
 
PPTX
Function C programming
Appili Vamsi Krishna
 
PDF
PL Lecture 04 - Expression and Statement
Schwannden Kuo
 
PPTX
AI: Planning and AI
DataminingTools Inc
 
PPTX
Functions in c language
Tanmay Modi
 
PPTX
Critical section problem in operating system.
MOHIT DADU
 
PDF
Password protected diary
SHARDA SHARAN
 
PPTX
Forloop
Dipen Vasoya
 
PDF
Files and streams
Pranali Chaudhari
 
PPTX
C tokens
Manu1325
 
PDF
Datasheet mis 701
Nguyễn Ngọc Tiên
 
DOCX
Grid view control
Paneliya Prince
 
PDF
C++ goto statement tutorialspoint
NAMITHNAVAKRISHNAN
 
PPTX
Implicit and explicit sequence control with exception handling
VIKASH MAINANWAL
 
DOC
Jumping statements
Suneel Dogra
 
Data Structure and Algorithms.pptx
Syed Zaid Irshad
 
Expert System (Forward and Backward Chaining)
Sohail Ahmed
 
C++ Class & object pointer in c++ programming language
HariTharshiniBscIT1
 
Access modifiers in java
Madishetty Prathibha
 
C- Programming Assignment 3
Animesh Chaturvedi
 
chapter-7-classes-and-objects.pdf
study material
 
Function C programming
Appili Vamsi Krishna
 
PL Lecture 04 - Expression and Statement
Schwannden Kuo
 
AI: Planning and AI
DataminingTools Inc
 
Functions in c language
Tanmay Modi
 
Critical section problem in operating system.
MOHIT DADU
 
Password protected diary
SHARDA SHARAN
 
Forloop
Dipen Vasoya
 
Files and streams
Pranali Chaudhari
 
C tokens
Manu1325
 
Datasheet mis 701
Nguyễn Ngọc Tiên
 
Grid view control
Paneliya Prince
 
C++ goto statement tutorialspoint
NAMITHNAVAKRISHNAN
 
Implicit and explicit sequence control with exception handling
VIKASH MAINANWAL
 
Jumping statements
Suneel Dogra
 

Similar to Unit 4- State Machine in mobile programming (20)

PDF
State Machine Workflow: Esoteric Techniques & Patterns Everyone Should Buy pr...
European SharePoint Conference
 
PPTX
Programming models for event controlled programs
Priya Kaushal
 
PPTX
State Machines and PLC Programming.pptx
Tobey Houston
 
PPTX
Application of embeddd system
Revathi Subramaniam
 
PPTX
Embedded system in washing machine
Vignesh Suresh
 
PPTX
States, state graphs and transition testing
ABHISHEK KUMAR
 
PDF
Zio in real world
Wiem Zine Elabidine
 
PPTX
Real World State And Notification Broker
XeDotNet
 
PPTX
Project Presentation - Mars Landing Simulation - Team A
Nicholi Gray
 
PPTX
Windows Phone 8 - 5 Application Lifecycle
Oliver Scheer
 
PDF
Discover finite state machines with gen_statem in Erlang /Elixir
Antoine REYT
 
PPTX
VIRA_Basics_of_Robot_Level_1.pptx
SarafrajBeg1
 
PPSX
Finite state automaton
AmmAr mobark
 
PPTX
Writing OS Updater App for Android
Aayush Gupta
 
PPTX
Autosys
Gagandeep Singh
 
PPTX
Application engine
JAYAARC
 
PPTX
Mgd finite statemachine
Moroccan game developers
 
PPTX
Process management in Operating System_Unit-2
mohanaps
 
PDF
State, State Graphs and Transition testing: state graphs, good & bad state gr...
Rajalingam Balakrishnan
 
PDF
20031109 WRUG Presentation
Manuel Sardinha
 
State Machine Workflow: Esoteric Techniques & Patterns Everyone Should Buy pr...
European SharePoint Conference
 
Programming models for event controlled programs
Priya Kaushal
 
State Machines and PLC Programming.pptx
Tobey Houston
 
Application of embeddd system
Revathi Subramaniam
 
Embedded system in washing machine
Vignesh Suresh
 
States, state graphs and transition testing
ABHISHEK KUMAR
 
Zio in real world
Wiem Zine Elabidine
 
Real World State And Notification Broker
XeDotNet
 
Project Presentation - Mars Landing Simulation - Team A
Nicholi Gray
 
Windows Phone 8 - 5 Application Lifecycle
Oliver Scheer
 
Discover finite state machines with gen_statem in Erlang /Elixir
Antoine REYT
 
VIRA_Basics_of_Robot_Level_1.pptx
SarafrajBeg1
 
Finite state automaton
AmmAr mobark
 
Writing OS Updater App for Android
Aayush Gupta
 
Application engine
JAYAARC
 
Mgd finite statemachine
Moroccan game developers
 
Process management in Operating System_Unit-2
mohanaps
 
State, State Graphs and Transition testing: state graphs, good & bad state gr...
Rajalingam Balakrishnan
 
20031109 WRUG Presentation
Manuel Sardinha
 
Ad

More from LeahRachael (15)

PPTX
UNIT 5-UNDERSTANDING THE OPERATION OF A NETWORK.pptx
LeahRachael
 
PPTX
UNIT 6-EXPLAINING THE ROLE OF THE NETWORK ADMINISTRATOR AND SUPPORT.pptx
LeahRachael
 
PPTX
UNIT 7-UNDERSTANDING LARGER NETWORKS.pptx
LeahRachael
 
PPTX
UNIT 3-DEMONSTRATING A COMPREHENSIVE UNDERSTANDING OF SOFTWARE DESIGN.pptx
LeahRachael
 
PPTX
UNIT 4 - UNDERSTANDING THE NETWORK ARCHITECTURE.pptx
LeahRachael
 
PPTX
UNIT 2- UNDERSTANDING DIGITAL SIGNALS PART 2
LeahRachael
 
PPTX
UNIT 2-APPLYING THE SOFTWARE COST ESTIMATION.pptx
LeahRachael
 
PPTX
UNIT 3 - EXPLAINING THE NEED OF COMPUTER NETWORK
LeahRachael
 
PPTX
UNIT 1-IDENTIFY THE NEED FOR SOFTWARE ENGINEERING DEVELOPMENT.pptx
LeahRachael
 
PPTX
Unit 1- PROGRAMMING IN C OPERATORS LECTURER NOTES
LeahRachael
 
PPTX
UNIT 5- UNDERSTANDING THE SYSTEM DESIGN PROCESS.pptx
LeahRachael
 
PPTX
UNIT 4-UNDERSTANDING VIRTUAL MEMORY.pptx
LeahRachael
 
PPTX
UNIT 3-EXPLAINING THE MEMORY MANAGEMENT LOGICAL AND AND PHYSICAL DATA FLOW DI...
LeahRachael
 
PPTX
UNIT 2-UNDERSTANDING THE SYNCHRONIZATION PROCESS.pptx
LeahRachael
 
PPTX
UNIT 1 - UNDERSTANDINGTHE PRINCIPLES OF OPERATING SYSTEM.pptx
LeahRachael
 
UNIT 5-UNDERSTANDING THE OPERATION OF A NETWORK.pptx
LeahRachael
 
UNIT 6-EXPLAINING THE ROLE OF THE NETWORK ADMINISTRATOR AND SUPPORT.pptx
LeahRachael
 
UNIT 7-UNDERSTANDING LARGER NETWORKS.pptx
LeahRachael
 
UNIT 3-DEMONSTRATING A COMPREHENSIVE UNDERSTANDING OF SOFTWARE DESIGN.pptx
LeahRachael
 
UNIT 4 - UNDERSTANDING THE NETWORK ARCHITECTURE.pptx
LeahRachael
 
UNIT 2- UNDERSTANDING DIGITAL SIGNALS PART 2
LeahRachael
 
UNIT 2-APPLYING THE SOFTWARE COST ESTIMATION.pptx
LeahRachael
 
UNIT 3 - EXPLAINING THE NEED OF COMPUTER NETWORK
LeahRachael
 
UNIT 1-IDENTIFY THE NEED FOR SOFTWARE ENGINEERING DEVELOPMENT.pptx
LeahRachael
 
Unit 1- PROGRAMMING IN C OPERATORS LECTURER NOTES
LeahRachael
 
UNIT 5- UNDERSTANDING THE SYSTEM DESIGN PROCESS.pptx
LeahRachael
 
UNIT 4-UNDERSTANDING VIRTUAL MEMORY.pptx
LeahRachael
 
UNIT 3-EXPLAINING THE MEMORY MANAGEMENT LOGICAL AND AND PHYSICAL DATA FLOW DI...
LeahRachael
 
UNIT 2-UNDERSTANDING THE SYNCHRONIZATION PROCESS.pptx
LeahRachael
 
UNIT 1 - UNDERSTANDINGTHE PRINCIPLES OF OPERATING SYSTEM.pptx
LeahRachael
 
Ad

Recently uploaded (20)

PPTX
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
PPTX
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
PDF
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
PPTX
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
PDF
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
PDF
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
PDF
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
PDF
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
PDF
AOMEI Partition Assistant Crack 10.8.2 + WinPE Free Downlaod New Version 2025
bashirkhan333g
 
PDF
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
PPTX
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
PDF
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
PPTX
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
PDF
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
PDF
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
PPTX
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
PPTX
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
PDF
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
AOMEI Partition Assistant Crack 10.8.2 + WinPE Free Downlaod New Version 2025
bashirkhan333g
 
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 

Unit 4- State Machine in mobile programming

  • 1. UNIT 4: UNDERSTANDING COMMUNICATIONS VIA NETWORK AND WEB State Machine
  • 2. A state machine • A state machine defines an application process flow at runtime. When you activate the application, the process flow is converted to a state machine. • A state machine main purpose is reading a series of inputs and switching to different states after reading a new input.
  • 3. Example: State machine • Fetching data from an endpoint. • The program can have 3 states: loading, success, and error. • A state machine also has a starting state, which coincidentally here is named “not started” but you can name it anything you want. • Here, the starting state indicates that the API is not called yet. • When a user opens a screen, the screen begins fetching the data, so the state moves to “loading”. • If the API call returns success/error, the state moves to SUCCESS/ERROR respectively. • After that, if the user refreshes the screen, the state goes back to LOADING. • We could call the annotation “fetch”, “error”, “success”, “refresh” an event or input. • The transition function receives the current state and an input and determines the next state.
  • 4. Example: State machine of a Washer Dryer • We want this machine to have 4 distinct states that we go from one to the next in this sequence: 1. Initial State – Where we are when we are waiting to start the wash 2. Wash – Where we wash with soap and water 3. Dry – Where we dry the clothes 4. Done
  • 5. State Diagram for Washer-Dryer Machine
  • 6. State Diagram for Washer-Dryer Machine… 1. We start at an “Initial” state whenever we start up the machine • Let’s also assume this stage is when you’d put in the soap and clothes • Once input “Coin is in” is 1, GTNS is now • This event triggers leaving the current state to go to the next state
  • 7. State Diagram for Washer-Dryer Machine… 2. This is followed by the next state, “Wash” • “Coin inserted” is now 0 at this point (so GTNS goes back to 0) • While soap is still present, GTNS goes back to 0 – When the input “Soap is no longer present” goes to 1, GTNS goes to 1 • This event triggers leaving the current state to go to the next state
  • 8. State Diagram for Washer-Dryer Machine… 3. This is followed by the next state, “Dry” • This new state sets an output that triggers a timer • The input “Soap is no longer present” goes to 0, so GTNS is 0 also • While the input “Clothes are now dry” is 0 , GTNS remains at 0 too • When the input “Clothes are now dry” is 1, GTNS changes to 1 • This event triggers leaving the current state to go to the next state
  • 9. 4. This is followed by the next and last state, “Done” • When you’re here, you go back to the “initial” state • No inputs to consider: you do move this regardless
  • 10. Components of a State Machine • A state machine consists of the following components: • State: basically a status of the machine. While being in a state, a machine waits for the event that will trigger a transition to a different state. • Event: the actual inputs that the machine reads. If we speak about a mobile application as an example, an event would be an action performed by the user. • Transition: the movement of the machine from one state to another after a certain event occurs.
  • 11. States of a state machine • States are elements of a state-machine system. • An application usually has many states, and can include different types of states. • Each state has a previous state and a following state, unless it is the initial state or the final state. • There can be only one initial state, but, depending on user interaction, there can be many final states.
  • 12. initial state • An initial state is the first state in an application, and only handles state transitions to follow-up states, based on transition rules. • The initial-state is Start Application, which is created automatically when you create an application, and cannot be deleted. • By default, the name of the initial state is the same as the name of the application.
  • 13. Finite State Machine/Synchronous state machine • A finite state machine is an abstract machine that can be in exactly one of a finite number of states at any given time. • Finite State Machine is a state machine, with a finite number of states. • It can be in one state at a time, and can transition to a different state once something happens. • A finite state machine must have: • an initial state which provides a starting point, and • a current state which remembers the product of the last state transition.
  • 14. Example: Finite State Machine Figure: state diagram
  • 15. Class Activity • Write a state transition table for the state machine diagram below
  • 16. Class Activity • Write a state transition table for the state machine diagram below
  • 17. Two types/models of FSM • Moore machine: its output is a function of present state only • Mealy machine: its output is a function of present state and present input
  • 18. its output is a function of present state only
  • 19. its output is a function of present state and present input
  • 20. Comparison of Mealy and Moore FSM
  • 21. Building a state machine for Android app • Step 1: Define the states • Step 2: Define the actions • Step 3: Connect the events with actions • Step 4: Write a bit of code • Step 5: Implement the states and build the activity • Example: • EventList+ AddEventClicked = AddEvent • AddEvent + EventSelected = NameEvent • NameEvent+ SubmitEventClicked = EventList
  • 22. The benefits of using state machine pattern in your mobile application • Allows developers to focus only on the configuration of states and transitions without digging into the “how” aspect of the process. • once a developer configures the needed states and the conditions for the transitions, the work is done and the machine will function in accordance with the set conditions. • Ensures a high level of predictability and eliminates the possibility of any malfunctions since every action is predefined. • It allows developers to visualize the work and makes the whole system more transparent. • Elimination of hard coding conditions in the code • Easy tracking of the processes due to the finite number of states and machine’s predictability • An option to isolate certain pieces of code due to the independency of every action • High stability of the system.
  • 23. Disadvantages of using state machine pattern in your mobile application • Not very suitable for asynchronous execution • Possibility to have complex code if several transitions are executed from one state • Limited support from the community • Tricky data management and storage • A possibility to obtain your own persistence layer in order to load balance properly
  • 24. You can look at feather explanation on state machine