State encapsulates varying behavior for the same routine based on an object's state object. StateMachine imposes a structure to automatically change the implementation from one object to the next. It keeps track of the current state, which is initialized by the constructor
Ref: