An Extensible State Machine Pattern for Interactive Applications

European Conference on Object-Oriented Programming (ECOOP 2008), Paphos, Cyprus, July 7-11, 2008.
Brian Chin, Todd Millstein
The state design pattern is the standard object-oriented programming idiom for implementing the state machine logic of interactive applications. While this pattern provides a number of advantages, it does not easily support the creation of extended state machines in subclasses. We describe the {\em extensible state design pattern, which augments the traditional state pattern with a few additional constraints that allow subclasses to easily add both new states and new events. Further, we observe that delimited continuations, a well-known construct from functional programming languages, supports state refinement in subclasses as well as the modular expression of control flow in the presence of interaction. We illustrate our pattern in the context of Java, leveraging its generics to obviate the need for dynamic typecasts and employing a small library that implements delimited continuations. We have used our pattern to simplify and modularize a widely used application written by others.

[PDF]