How to implement a FSM – Finite State Machine in Java

The heart of a state machine is the transition table, which takes a state and a symbol (what you’re calling an event) to a new state. That’s just a two-index array of states. For sanity and type safety, declare the states and symbols as enumerations. I always add a “length” member in some way (language-specific) … Read more

How to use state pattern correctly?

@Ivan: There are a number of resources available on the web for Hierarchical State Machines (HSM). Miro Samek has written extensively about this design pattern and offers a lot of helpful information. Some articles that should be of interest: State-Oriented Programming (SOP) (Samek) (pdf) Hierarchical State Machines – a Fundamentally Important Way of Design (Samek) … Read more

What is the difference between a state machine and the implementation of the state pattern?

The way I describe this difference to my colleagues is that state patterns are a more decentralized implementation of many stand alone encapsulated states whereas state machines are more monolithic. The monolithic nature of state machines means that a single state will be harder to reuse in a different machine and that it is harder … Read more

What is the difference between Strategy design pattern and State design pattern?

Honestly, the two patterns are pretty similar in practice, and the defining difference between them tends to vary depending on who you ask. Some popular choices are: States store a reference to the context object that contains them. Strategies do not. States are allowed to replace themselves (IE: to change the state of the context … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)