Finite State Machine Patterns

Sherif M. Yacoub; Hany H. Ammar
Computer Science and Electrical Engineering Department
West Virginia University, Morgantown
West Virginia, WV26506

Introduction

Finite state machines (FSM) are widely used in many reactive systems to describe the dynamic behavior of an object based on its state. The theoretical concepts of FSMs and an object's specifications, in terms of state transition diagrams, have long been used. Here, we show how to solve several recurring design problems in implementing a state machine. A basic design pattern for finite state machines is presented, its design evolves from the general understanding of state machines functionality. Then the basic pattern is extended to support solutions to several design problems that are commonly thought of by system designers. These design decisions include the state-transition mechanisms, the design structure, state-instantiation techniques, and the machine type. Since finite state machines are frequently applicable to areas of concurrent and real-time software, thus it is useful for the system designer to search a catalog of classified state machine patterns. The patterns cover the three-layer FSM pattern by Robert Martin5 and extend the set of patterns described by Paul Dyson and Bruce Andreson 2.