The state design pattern is a way for an object to change its behavior at runtime according to its internal state "without resorting to large conditional statements or table lookups" thanks to virtual function calls. Its main advantage over code using large conditional statements is that state-specific code is distributed across different objects rather than localized in a monolithic block, which improves maintainability. Its main advantages over code using state-transition tables are that virtual function calls are often more efficient than table lookups, that state-transition criteria are more explicit than in tabular format, and that it is easier to add actions accompanying state transitions. However it introduces a new problem: the number of classes makes the code less compact than the other approaches. The program using the state design pattern could look like this:  class StateMachine; class State {  class Before: public State {  class Inside: public State {  class After: public State {  class StateMachine {  State const* Before::instantiate() {  void Before::feedChar(StateMachine* const m, int const c) const { State const* Before::_instance = nullptr; State const* Inside::instantiate() {  void Inside::feedChar(StateMachine* const m, int const c) const { State const* Inside::_instance = nullptr; State const* After::instantiate() {  void After::feedChar(StateMachine* const m, int const c) const { State const* After::_instance = nullptr; void StateMachine::feedChar(int const c) {  void StateMachine::setState(State const* const s) {  int main() {  Automata-based programming indeed closely matches the programming needs found in the field of automation. A production cycle is commonly modelled as:  Various dedicated programming languages allow expressing such a model in more or less sophisticated ways. The example presented above could be expressed according to this view like in the following pseudo-code ('set' activates a logic variable, 'reset' inactivates a logic variable, ':' assigns a variable, and '=' tests for equality): newline: '\n' whitespace: ('\t', '\n', '\v', '\f', '\r', ' ') states: (before, inside, after) setState(c) {  doAction(c) {  cycle {  The separation of routines expressing cycle progression on one side, and actual action on the other (matching input and output) allows clearer and simpler code.