Tuesday, 19 April 2016

State Machines (FSM)

What is State machine?
We use a state machine to represent a (real or logical) object that can exist in a limited number of conditions ("states") and progresses from one state to the next according to a fixed set of rules.The output of one state depends on its input.

You have states which are object state and events which are methods that cause transitions from one state to another

Why use it?
It will reduce the logical complexity of that object's implementation.
Suppose for saving a data through an object, the object has to go through multiple states
Init
Saving
Save
Idle
and complexity is more for object implementation then we have to look for state machines.

In javascript, i have used a library
https://github.com/jakesgordon/javascript-state-machine to implement state machines

References & Good Articles
https://engineering.shopify.com/17488160-why-developers-should-be-force-fed-state-machines
http://stackoverflow.com/questions/255797/uses-for-state-machines
http://www.skorks.com/2011/09/why-developers-never-use-state-machines/

No comments:

Post a Comment