title: What is the best way, using the "State" design pattern, to change states?
body: <p>My current understanding of the State design pattern is basically this: </p>
  
  <p>Encapsulate all of the behavior of an object in a particular state in an object. Delegate requests to the "Current" state object.</p>
  
  <p>My question is: What is the best way to handle state transitions? In my case, it is likely that "Current" state object will be the one who decides to what other state we need to transition to. I've thought of 2 ways of implementing this:</p>
  
  <ol>
  <li><p>The state objects methods can return some particular value that means "I'm requesting a state transition". The main object can then query the current state for what new state we should transition to, call <code>ChangeState()</code>, and then route the original request to the new state.</p></li>
  <li><p>The state object itself can call <code>ChangeState()</code> on the parent, and then itself pass the request that caused the state change on to the new object.</p></li>
  </ol>
  
  <p>Scenario 2 has the advantage that the main object needs only ever delegate requests to the "Current" state (it internally will handle any necessary state transitions). It is also perhaps a little less obvious.</p>
  
  <p>I'm hoping there are known better ways of handling this scenario. What do you think?</p>