<p><pre><code>  &gt; The humble state machine is a more important part of programming
  &gt; than people like to admit
</code></pre>
Here is where I feel a lot of OOP applications are “doing statefullness wrong.” Everyone gloms onto the popular GoF patterns, but explicit state machines are not nearly popular enough.<p>A colleague once remarked that in business programming, every model should be a state machine until you can demonstrate you can do without. For example, many Ruby on Rails models have a concept of validation. Most such models can be greatly improved by treating “invalid” as an explicit state with its own methods and behaviours distinct from the methods and behaviours of a valid model (which may encompass other states as well).<p>I find that if you’re going to have state, go all the way, reify it, make it something you can name and manipulate. Implicit state is the GOTO-ridden spaghetti-code of imperative programming style.