Implementing a state engine using instance behaviour
Created 2006-12-11T09:48:09.050Z, last edited 2006-12-11T09:48:09.128Z
State engines are a pretty useful, but underutilised programming technique. Most common ways of implementing them tend to give pretty messy code.
Part of the problem is of course the impedance mismatch between the programming languages we use and the state engine. Even in object oriented languages we normally see state engines implemented in terms of a switch statement which grows to gargantuan proportions.
What I'm going to do is to show how to neaten these implementations up by making use of an advanced object-oriented technique called instance behaviour.
© 2002-2025 Kirit & Tai Sælensminde. All forum posts are copyright their respective authors.
Licensed under a Creative Commons License. Non-commercial use is fine so long as you provide attribution.