SlideShare a Scribd company logo
10
Most read
21
Most read
23
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

PDF
DELD Unit IV ring and twisted ring counter
PPT
Expert System Full Details
PPTX
Operand and Opcode | Computer Science
PPT
Moore and Mealy machines
PPTX
Chapter 03 arithmetic for computers
PPTX
Pipelining of Processors Computer Architecture
PPTX
Machine Translation
PPT
Memory management ppt coa
DELD Unit IV ring and twisted ring counter
Expert System Full Details
Operand and Opcode | Computer Science
Moore and Mealy machines
Chapter 03 arithmetic for computers
Pipelining of Processors Computer Architecture
Machine Translation
Memory management ppt coa

What's hot (20)

PPTX
Nand and nor
PDF
Finite state machine based vending machine IEEE Paper
PDF
HDFC banking system SRS Document
PDF
Solution manual of assembly language programming and organization of the ibm ...
PPTX
Direct memory access (dma) with 8257 DMA Controller
PPTX
COA asynchronous data transfer
PPTX
Microprocessor 8085 complete
PPTX
PDF
Chat bot in_pythion
PPTX
Addressing modes of 8086 - Binu Joy
PPTX
Chapter 6: Sequential Logic
PDF
Associative Memory using NN (Soft Computing)
PDF
Project Report Format College Project
PDF
Unit 3 – assembly language programming
PDF
8155 PPI
PDF
Combinational Circuits PPT.pdf
PPTX
Part I:Introduction to assembly language
PDF
PPT
8251 universal synchronous asynchronous receiver transmitter
PPTX
priority interrupt computer organization
Nand and nor
Finite state machine based vending machine IEEE Paper
HDFC banking system SRS Document
Solution manual of assembly language programming and organization of the ibm ...
Direct memory access (dma) with 8257 DMA Controller
COA asynchronous data transfer
Microprocessor 8085 complete
Chat bot in_pythion
Addressing modes of 8086 - Binu Joy
Chapter 6: Sequential Logic
Associative Memory using NN (Soft Computing)
Project Report Format College Project
Unit 3 – assembly language programming
8155 PPI
Combinational Circuits PPT.pdf
Part I:Introduction to assembly language
8251 universal synchronous asynchronous receiver transmitter
priority interrupt computer organization
Ad

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

PPTX
Mgd finite statemachine
PPTX
Programming models for event controlled programs
PPT
States and Activities
DOCX
UNIT-IV .FINITE STATE MACHINES
PPTX
State-Machine-Diagram.pptx
PPTX
States, state graphs and transition testing
PPTX
Sometimes tells me funny stories from his childhood
PPTX
Finite State Machines Digital Logic Design .pptx
PPTX
mealy and moore machines
PPTX
Finite State Machine.ppt.pptx
PDF
"Mastering UI Complexity: State Machines and Reactive Patterns at Grammarly",...
PPTX
Design Summit - Intro to State Machines - John Hardy
PDF
Qt State Machine Framework
PPT
Fdocuments.in chapter 11-states-state-graphs-and-transition-testing
PPT
State Machine Diagram
PPT
chap8 synchronous sequential circuit design.ppt
PPTX
events and signals in Unified modelling language
PDF
State Machine Framework
PPTX
State machines1
PPT
Logic and computer design.ppt
Mgd finite statemachine
Programming models for event controlled programs
States and Activities
UNIT-IV .FINITE STATE MACHINES
State-Machine-Diagram.pptx
States, state graphs and transition testing
Sometimes tells me funny stories from his childhood
Finite State Machines Digital Logic Design .pptx
mealy and moore machines
Finite State Machine.ppt.pptx
"Mastering UI Complexity: State Machines and Reactive Patterns at Grammarly",...
Design Summit - Intro to State Machines - John Hardy
Qt State Machine Framework
Fdocuments.in chapter 11-states-state-graphs-and-transition-testing
State Machine Diagram
chap8 synchronous sequential circuit design.ppt
events and signals in Unified modelling language
State Machine Framework
State machines1
Logic and computer design.ppt
Ad

More from LeahRachael (15)

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

Recently uploaded (20)

PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
System and Network Administraation Chapter 3
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
medical staffing services at VALiNTRY
PPTX
Odoo POS Development Services by CandidRoot Solutions
PPTX
L1 - Introduction to python Backend.pptx
PDF
AI in Product Development-omnex systems
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
Nekopoi APK 2025 free lastest update
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Understanding Forklifts - TECH EHS Solution
PDF
PTS Company Brochure 2025 (1).pdf.......
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Operating system designcfffgfgggggggvggggggggg
System and Network Administraation Chapter 3
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Design an Analysis of Algorithms II-SECS-1021-03
medical staffing services at VALiNTRY
Odoo POS Development Services by CandidRoot Solutions
L1 - Introduction to python Backend.pptx
AI in Product Development-omnex systems
Odoo Companies in India – Driving Business Transformation.pdf
Adobe Illustrator 28.6 Crack My Vision of Vector Design
wealthsignaloriginal-com-DS-text-... (1).pdf
Nekopoi APK 2025 free lastest update
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Wondershare Filmora 15 Crack With Activation Key [2025
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Understanding Forklifts - TECH EHS Solution
PTS Company Brochure 2025 (1).pdf.......
VVF-Customer-Presentation2025-Ver1.9.pptx

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