Architecting Your Project with a Finite-State Machine

45170771ad3f81f46a94dd4d4776b29d?s=47 Patrick Seda
February 24, 2017

Architecting Your Project with a Finite-State Machine

45170771ad3f81f46a94dd4d4776b29d?s=128

Patrick Seda

February 24, 2017
Tweet

Transcript

  1. Architecting Your Project with a Finite-State Machine DEVNEXUS Atlanta –

    February 24, 2017
  2. Patrick Seda @pxtrick - CTO of Colligo Vox - Mobile/Technology

    Solutions Consulting - 25+ Years as a Software Professional - Apps: Enterprise to Children’s games
  3. None
  4. None
  5. Track State ? How Do We

  6. Booleans, Constants, Strings

  7. None
  8. Finite-State Machine!

  9. -  Abstract machine -  Can be in exactly one of

    a finite number of states at a time -  State changes via input events -  Transitions -  Module finite-state machine
  10. finite-state machine Door Closed Door Open open close

  11. Configuring The FSM

  12. configuring // JSON example ... var config = { states:

    { ‘DoorClosed’: { events: { ‘open’: { toState: ‘DoorOpen’} } }, ‘DoorOpen’: { events: { ‘close’: { toState: ‘DoorClosed’} } } }, startState: ‘DoorClosed’ };
  13. Home Security System! Let’s Design a

  14. a security system

  15. A Honeywell Security System

  16. Armed Stay Armed Away Armed Max Exit Delay? Entry Delay?

    Motion? No Yes Yes Yes Yes No No Yes Yes Armed Instant No No No a honeywell system
  17. “Armed Away” a honeywell system

  18. “Armed Max” a honeywell system

  19. “Armed Stay” a honeywell system

  20. “Armed Instant” a honeywell system

  21. a honeywell system

  22. The State Pattern

  23. state pattern •  Separates interface from implementation •  Enables interchangeable

    behavior •  Perfect for a state machine! Context State State A State B handle() handle() handle()
  24. state pattern Handler State Armed Disarmed handle() handle() handle() Alarming

    handle() for our home security system …
  25. The System In Motion

  26. Architectural Big Picture

  27. big picture Event Handler Disarmed State State State Armed FSM

  28. big picture Visual Status Audible Status Emergency Services Web Backend

    Keypad Sensors
  29. None
  30. patrick.seda@colligovox.com linkedin.com/in/patrickseda speakerdeck.com/pxtrick podcast: techmatters.fm Patrick Seda @pxtrick