SlideShare une entreprise Scribd logo
1  sur  12
STATE MACHINES ,[object Object],codeofficer.com github.com/code officer twitter.com/co deofficer
State Machines? A model of behavior composed of a finite number of states, transitions between those states, and actions. A finite state machine is an abstract model of a machine with a primitive internal memory. http://en.wikipedia.org/wiki/Finite_state_machine
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Common Uses?
[object Object],[object Object],[object Object],[object Object],So, What’s in a State Machine?
Machines? ,[object Object],[object Object],[object Object]
States? ,[object Object],[object Object],[object Object],[object Object]
Events? ,[object Object],[object Object]
Gems and Plugins State Machine A plugin By Aaron Pfeifer (pluginaweek) http://github.com/pluginaweek/state_machine/ http://api.pluginaweek.org/state_machine/ Acts As State Machine A gem By Scott Barron http://github.com/rubyist/aasm/ Which state machine project will have the most github watchers by RailsConf 2009? https://opensource.inklingmarkets.com/markets/18368
A Simple Machine (using the State Machine plugin) (using the State Machine plugin) class  Light < ActiveRecord::Base   attr_accessor  :intensity   state_machine :state, :initial =>:off  do   state :off  {  def  intensity; 0;  end  }   state :low  {  def  intensity; 5;  end  }   state :high {  def  intensity; 10;  end  }   event :switch  do   transition :off => :low, :low => :high, :high => :off   end   end end @light = Light.new @light.state  #=> “off” @light.intensity  #=> 0 @light.off?  #=> true @light.can_switch?  #=> true @light.switch!  #=> true @light.state  #=> “low” @light.intensity  #=> 5 @light.off?  #=> false @light.can_switch?  #=> true @light.switch! # repeat and rinse ...
Another Machine (also using the State Machine plugin) (also using the State Machine plugin) class   Vehicle   state_machine  :initial  =>  :parked   do   event  :park   do   transition [ :idling ,  :first_gear ] =>  :parked   end     event  :ignite   do   transition  :stalled  => same,  :parked  =>  :idling   end     event  :idle   do   transition  :first_gear  =>  :idling   end     event  :shift_up   do   transition  :idling  =>  :first_gear ,  :first_gear  =>  :second_gear ,  :second_gear  =>  :third_gear   end     event  :shift_down   do   transition  :third_gear  =>  :second_gear ,  :second_gear  =>  :first_gear   end     event  :crash   do   transition [ :first_gear ,  :second_gear ,  :third_gear ] =>  :stalled   end     event  :repair   do   transition  :stalled  =>  :parked   end   end end
Machine Integrations (for the State Machine plugin) (for the State Machine plugin) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Textmate Bundles ,[object Object],[object Object],[object Object],[object Object],Auto completion for machines, events,  transitions and callbacks

Contenu connexe

Tendances

Introduction to Redux (for Angular and React devs)
Introduction to Redux (for Angular and React devs)Introduction to Redux (for Angular and React devs)
Introduction to Redux (for Angular and React devs)Fabio Biondi
 
Anatomy of a Reactive Application
Anatomy of a Reactive ApplicationAnatomy of a Reactive Application
Anatomy of a Reactive ApplicationMark Wilson
 
An Overview of the React Ecosystem
An Overview of the React EcosystemAn Overview of the React Ecosystem
An Overview of the React EcosystemFITC
 
Introduction to React Hooks
Introduction to React HooksIntroduction to React Hooks
Introduction to React HooksFelicia O'Garro
 
React js t7 - forms-events
React js   t7 - forms-eventsReact js   t7 - forms-events
React js t7 - forms-eventsJainul Musani
 
React + Redux. Best practices
React + Redux.  Best practicesReact + Redux.  Best practices
React + Redux. Best practicesClickky
 
Building user interface with react
Building user interface with reactBuilding user interface with react
Building user interface with reactAmit Thakkar
 
Evan Schultz - Angular Summit - 2016
Evan Schultz - Angular Summit - 2016Evan Schultz - Angular Summit - 2016
Evan Schultz - Angular Summit - 2016Evan Schultz
 
Ryan Christiani I Heard React Was Good
Ryan Christiani I Heard React Was GoodRyan Christiani I Heard React Was Good
Ryan Christiani I Heard React Was GoodFITC
 
Fabio Biondi - Front-end data architectures in Angular, Redux & NGRX - Codemo...
Fabio Biondi - Front-end data architectures in Angular, Redux & NGRX - Codemo...Fabio Biondi - Front-end data architectures in Angular, Redux & NGRX - Codemo...
Fabio Biondi - Front-end data architectures in Angular, Redux & NGRX - Codemo...Codemotion
 
Pluginkla2019 - React Presentation
Pluginkla2019 - React PresentationPluginkla2019 - React Presentation
Pluginkla2019 - React PresentationAngela Lehru
 
Reactotron - A Debugging Agent
Reactotron -  A Debugging AgentReactotron -  A Debugging Agent
Reactotron - A Debugging AgentMatthieu Vachon
 
Programação reativa functional com java 8
Programação reativa functional com java 8Programação reativa functional com java 8
Programação reativa functional com java 8Diego Pacheco
 
Refactoring Design Patterns the Functional Way (in Scala)
Refactoring Design Patterns the Functional Way (in Scala)Refactoring Design Patterns the Functional Way (in Scala)
Refactoring Design Patterns the Functional Way (in Scala)Kfir Bloch
 

Tendances (17)

Ngrx slides
Ngrx slidesNgrx slides
Ngrx slides
 
Introduction to Redux (for Angular and React devs)
Introduction to Redux (for Angular and React devs)Introduction to Redux (for Angular and React devs)
Introduction to Redux (for Angular and React devs)
 
Anatomy of a Reactive Application
Anatomy of a Reactive ApplicationAnatomy of a Reactive Application
Anatomy of a Reactive Application
 
An Overview of the React Ecosystem
An Overview of the React EcosystemAn Overview of the React Ecosystem
An Overview of the React Ecosystem
 
Redux essentials
Redux essentialsRedux essentials
Redux essentials
 
Introduction to React Hooks
Introduction to React HooksIntroduction to React Hooks
Introduction to React Hooks
 
React js t7 - forms-events
React js   t7 - forms-eventsReact js   t7 - forms-events
React js t7 - forms-events
 
React js t5 - state
React js   t5 - stateReact js   t5 - state
React js t5 - state
 
React + Redux. Best practices
React + Redux.  Best practicesReact + Redux.  Best practices
React + Redux. Best practices
 
Building user interface with react
Building user interface with reactBuilding user interface with react
Building user interface with react
 
Evan Schultz - Angular Summit - 2016
Evan Schultz - Angular Summit - 2016Evan Schultz - Angular Summit - 2016
Evan Schultz - Angular Summit - 2016
 
Ryan Christiani I Heard React Was Good
Ryan Christiani I Heard React Was GoodRyan Christiani I Heard React Was Good
Ryan Christiani I Heard React Was Good
 
Fabio Biondi - Front-end data architectures in Angular, Redux & NGRX - Codemo...
Fabio Biondi - Front-end data architectures in Angular, Redux & NGRX - Codemo...Fabio Biondi - Front-end data architectures in Angular, Redux & NGRX - Codemo...
Fabio Biondi - Front-end data architectures in Angular, Redux & NGRX - Codemo...
 
Pluginkla2019 - React Presentation
Pluginkla2019 - React PresentationPluginkla2019 - React Presentation
Pluginkla2019 - React Presentation
 
Reactotron - A Debugging Agent
Reactotron -  A Debugging AgentReactotron -  A Debugging Agent
Reactotron - A Debugging Agent
 
Programação reativa functional com java 8
Programação reativa functional com java 8Programação reativa functional com java 8
Programação reativa functional com java 8
 
Refactoring Design Patterns the Functional Way (in Scala)
Refactoring Design Patterns the Functional Way (in Scala)Refactoring Design Patterns the Functional Way (in Scala)
Refactoring Design Patterns the Functional Way (in Scala)
 

En vedette

Finite state machines
Finite state machinesFinite state machines
Finite state machinesdennis gookyi
 
Finite State Machines
Finite State Machines Finite State Machines
Finite State Machines Basel Mansour
 
Moore and mealy machines
Moore and mealy machinesMoore and mealy machines
Moore and mealy machineslavishka_anuj
 
Finite state machines
Finite state machinesFinite state machines
Finite state machinesgrahamwell
 
Introduction state machine
Introduction state machineIntroduction state machine
Introduction state machineShreyans Pathak
 
Moore and Mealy machines
Moore and Mealy machinesMoore and Mealy machines
Moore and Mealy machinesIrfan Anjum
 
Feedback Sequential Circuits
Feedback Sequential CircuitsFeedback Sequential Circuits
Feedback Sequential CircuitsAbhilash Nair
 
Designing State Machine
Designing State MachineDesigning State Machine
Designing State MachineAbhilash Nair
 
Designing Clocked Synchronous State Machine
Designing Clocked Synchronous State MachineDesigning Clocked Synchronous State Machine
Designing Clocked Synchronous State MachineAbhilash Nair
 
State Machine Design and Synthesis
State Machine Design and SynthesisState Machine Design and Synthesis
State Machine Design and SynthesisAbhilash Nair
 
Software Engineering - Ch8
Software Engineering - Ch8Software Engineering - Ch8
Software Engineering - Ch8Siddharth Ayer
 
Introduction to fa and dfa
Introduction to fa  and dfaIntroduction to fa  and dfa
Introduction to fa and dfadeepinderbedi
 
Mealy and moore machines
Mealy and moore machinesMealy and moore machines
Mealy and moore machinesgrahamwell
 
Synchronous state machines. Moore and Mealy state machines (FSM)
Synchronous state machines.  Moore and Mealy state machines (FSM)Synchronous state machines.  Moore and Mealy state machines (FSM)
Synchronous state machines. Moore and Mealy state machines (FSM)Mumbi Chishimba
 

En vedette (20)

Finite state machines
Finite state machinesFinite state machines
Finite state machines
 
Finite State Machines
Finite State Machines Finite State Machines
Finite State Machines
 
Moore and mealy machines
Moore and mealy machinesMoore and mealy machines
Moore and mealy machines
 
Finite Automata
Finite AutomataFinite Automata
Finite Automata
 
Finite state machines
Finite state machinesFinite state machines
Finite state machines
 
Finite State Machines - Why the fear?
Finite State Machines - Why the fear?Finite State Machines - Why the fear?
Finite State Machines - Why the fear?
 
Introduction state machine
Introduction state machineIntroduction state machine
Introduction state machine
 
Moore and Mealy machines
Moore and Mealy machinesMoore and Mealy machines
Moore and Mealy machines
 
Feedback Sequential Circuits
Feedback Sequential CircuitsFeedback Sequential Circuits
Feedback Sequential Circuits
 
Designing State Machine
Designing State MachineDesigning State Machine
Designing State Machine
 
Sequence Diagram
Sequence DiagramSequence Diagram
Sequence Diagram
 
Designing Clocked Synchronous State Machine
Designing Clocked Synchronous State MachineDesigning Clocked Synchronous State Machine
Designing Clocked Synchronous State Machine
 
State Machine Design and Synthesis
State Machine Design and SynthesisState Machine Design and Synthesis
State Machine Design and Synthesis
 
Deterministic Finite Automata
Deterministic Finite AutomataDeterministic Finite Automata
Deterministic Finite Automata
 
Software Engineering - Ch8
Software Engineering - Ch8Software Engineering - Ch8
Software Engineering - Ch8
 
Finite automata
Finite automataFinite automata
Finite automata
 
Introduction to fa and dfa
Introduction to fa  and dfaIntroduction to fa  and dfa
Introduction to fa and dfa
 
EPROM, PROM & ROM
EPROM, PROM & ROMEPROM, PROM & ROM
EPROM, PROM & ROM
 
Mealy and moore machines
Mealy and moore machinesMealy and moore machines
Mealy and moore machines
 
Synchronous state machines. Moore and Mealy state machines (FSM)
Synchronous state machines.  Moore and Mealy state machines (FSM)Synchronous state machines.  Moore and Mealy state machines (FSM)
Synchronous state machines. Moore and Mealy state machines (FSM)
 

Similaire à Introduction to State Machines

Composite Applications with WPF and PRISM
Composite Applications with WPF and PRISMComposite Applications with WPF and PRISM
Composite Applications with WPF and PRISMEyal Vardi
 
Sessionizing Uber Trips in Realtime - Flink Forward '18, Berlin
Sessionizing Uber Trips in Realtime  - Flink Forward '18, BerlinSessionizing Uber Trips in Realtime  - Flink Forward '18, Berlin
Sessionizing Uber Trips in Realtime - Flink Forward '18, BerlinAmey Chaugule
 
C:\documents and settings\student\desktop\swaroop uml
C:\documents and settings\student\desktop\swaroop umlC:\documents and settings\student\desktop\swaroop uml
C:\documents and settings\student\desktop\swaroop umlsatyaiswaroop
 
Flink Forward Berlin 2018: Amey Chaugule - "Threading Needles in a Haystack: ...
Flink Forward Berlin 2018: Amey Chaugule - "Threading Needles in a Haystack: ...Flink Forward Berlin 2018: Amey Chaugule - "Threading Needles in a Haystack: ...
Flink Forward Berlin 2018: Amey Chaugule - "Threading Needles in a Haystack: ...Flink Forward
 
Tech_Implementation of Complex ITIM Workflows
Tech_Implementation of Complex ITIM WorkflowsTech_Implementation of Complex ITIM Workflows
Tech_Implementation of Complex ITIM Workflows51 lecture
 
Ruslan Platonov - Transactions
Ruslan Platonov - TransactionsRuslan Platonov - Transactions
Ruslan Platonov - TransactionsDmitry Buzdin
 
Stateful streaming data pipelines
Stateful streaming data pipelinesStateful streaming data pipelines
Stateful streaming data pipelinesTimothy Farkas
 
Introducing Struts 2
Introducing Struts 2Introducing Struts 2
Introducing Struts 2wiradikusuma
 
React state managmenet with Redux
React state managmenet with ReduxReact state managmenet with Redux
React state managmenet with ReduxVedran Blaženka
 
GTLAB Installation Tutorial for SciDAC 2009
GTLAB Installation Tutorial for SciDAC 2009GTLAB Installation Tutorial for SciDAC 2009
GTLAB Installation Tutorial for SciDAC 2009marpierc
 
Ob1k presentation at Java.IL
Ob1k presentation at Java.ILOb1k presentation at Java.IL
Ob1k presentation at Java.ILEran Harel
 
WebPerformance: Why and How? – Stefan Wintermeyer
WebPerformance: Why and How? – Stefan WintermeyerWebPerformance: Why and How? – Stefan Wintermeyer
WebPerformance: Why and How? – Stefan WintermeyerElixir Club
 
Generalized Functors - Realizing Command Design Pattern in C++
Generalized Functors - Realizing Command Design Pattern in C++Generalized Functors - Realizing Command Design Pattern in C++
Generalized Functors - Realizing Command Design Pattern in C++ppd1961
 
Adventurous Merb
Adventurous MerbAdventurous Merb
Adventurous MerbMatt Todd
 
Windows Azure - Cloud Service Development Best Practices
Windows Azure - Cloud Service Development Best PracticesWindows Azure - Cloud Service Development Best Practices
Windows Azure - Cloud Service Development Best PracticesSriram Krishnan
 

Similaire à Introduction to State Machines (20)

Act as state machine
Act as state machineAct as state machine
Act as state machine
 
JavaScript
JavaScriptJavaScript
JavaScript
 
Composite Applications with WPF and PRISM
Composite Applications with WPF and PRISMComposite Applications with WPF and PRISM
Composite Applications with WPF and PRISM
 
Sessionizing Uber Trips in Realtime - Flink Forward '18, Berlin
Sessionizing Uber Trips in Realtime  - Flink Forward '18, BerlinSessionizing Uber Trips in Realtime  - Flink Forward '18, Berlin
Sessionizing Uber Trips in Realtime - Flink Forward '18, Berlin
 
C:\documents and settings\student\desktop\swaroop uml
C:\documents and settings\student\desktop\swaroop umlC:\documents and settings\student\desktop\swaroop uml
C:\documents and settings\student\desktop\swaroop uml
 
Flink Forward Berlin 2018: Amey Chaugule - "Threading Needles in a Haystack: ...
Flink Forward Berlin 2018: Amey Chaugule - "Threading Needles in a Haystack: ...Flink Forward Berlin 2018: Amey Chaugule - "Threading Needles in a Haystack: ...
Flink Forward Berlin 2018: Amey Chaugule - "Threading Needles in a Haystack: ...
 
Riding Apache Camel
Riding Apache CamelRiding Apache Camel
Riding Apache Camel
 
Tech_Implementation of Complex ITIM Workflows
Tech_Implementation of Complex ITIM WorkflowsTech_Implementation of Complex ITIM Workflows
Tech_Implementation of Complex ITIM Workflows
 
Ruslan Platonov - Transactions
Ruslan Platonov - TransactionsRuslan Platonov - Transactions
Ruslan Platonov - Transactions
 
Retrofitting
RetrofittingRetrofitting
Retrofitting
 
Stateful streaming data pipelines
Stateful streaming data pipelinesStateful streaming data pipelines
Stateful streaming data pipelines
 
Introducing Struts 2
Introducing Struts 2Introducing Struts 2
Introducing Struts 2
 
05 Transactions
05 Transactions05 Transactions
05 Transactions
 
React state managmenet with Redux
React state managmenet with ReduxReact state managmenet with Redux
React state managmenet with Redux
 
GTLAB Installation Tutorial for SciDAC 2009
GTLAB Installation Tutorial for SciDAC 2009GTLAB Installation Tutorial for SciDAC 2009
GTLAB Installation Tutorial for SciDAC 2009
 
Ob1k presentation at Java.IL
Ob1k presentation at Java.ILOb1k presentation at Java.IL
Ob1k presentation at Java.IL
 
WebPerformance: Why and How? – Stefan Wintermeyer
WebPerformance: Why and How? – Stefan WintermeyerWebPerformance: Why and How? – Stefan Wintermeyer
WebPerformance: Why and How? – Stefan Wintermeyer
 
Generalized Functors - Realizing Command Design Pattern in C++
Generalized Functors - Realizing Command Design Pattern in C++Generalized Functors - Realizing Command Design Pattern in C++
Generalized Functors - Realizing Command Design Pattern in C++
 
Adventurous Merb
Adventurous MerbAdventurous Merb
Adventurous Merb
 
Windows Azure - Cloud Service Development Best Practices
Windows Azure - Cloud Service Development Best PracticesWindows Azure - Cloud Service Development Best Practices
Windows Azure - Cloud Service Development Best Practices
 

Dernier

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 

Dernier (20)

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 

Introduction to State Machines

  • 1.
  • 2. State Machines? A model of behavior composed of a finite number of states, transitions between those states, and actions. A finite state machine is an abstract model of a machine with a primitive internal memory. http://en.wikipedia.org/wiki/Finite_state_machine
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8. Gems and Plugins State Machine A plugin By Aaron Pfeifer (pluginaweek) http://github.com/pluginaweek/state_machine/ http://api.pluginaweek.org/state_machine/ Acts As State Machine A gem By Scott Barron http://github.com/rubyist/aasm/ Which state machine project will have the most github watchers by RailsConf 2009? https://opensource.inklingmarkets.com/markets/18368
  • 9. A Simple Machine (using the State Machine plugin) (using the State Machine plugin) class Light < ActiveRecord::Base attr_accessor :intensity state_machine :state, :initial =>:off do state :off { def intensity; 0; end } state :low { def intensity; 5; end } state :high { def intensity; 10; end } event :switch do transition :off => :low, :low => :high, :high => :off end end end @light = Light.new @light.state #=> “off” @light.intensity #=> 0 @light.off? #=> true @light.can_switch? #=> true @light.switch! #=> true @light.state #=> “low” @light.intensity #=> 5 @light.off? #=> false @light.can_switch? #=> true @light.switch! # repeat and rinse ...
  • 10. Another Machine (also using the State Machine plugin) (also using the State Machine plugin) class Vehicle state_machine :initial => :parked do event :park do transition [ :idling , :first_gear ] => :parked end event :ignite do transition :stalled => same, :parked => :idling end event :idle do transition :first_gear => :idling end event :shift_up do transition :idling => :first_gear , :first_gear => :second_gear , :second_gear => :third_gear end event :shift_down do transition :third_gear => :second_gear , :second_gear => :first_gear end event :crash do transition [ :first_gear , :second_gear , :third_gear ] => :stalled end event :repair do transition :stalled => :parked end end end
  • 11.
  • 12.