Finite State Machines and The State Pattern

Clean Code, Episode 28

By Robert C. Martin

73 minOct 2014

Come all without. Come all within. You've not seen nothing like the mighty FSM.

This episode is all about Finite State Machines. What they are. Why and when to use them. How to represent them. And how to implement them. Including implementing them with The State Pattern.

Yes, this is part of our series on Design Patterns. It's also the first in at least three parts that will lead us from the State pattern to the Visitor pattern.

It's going to be an interesting journey. We begin it here by talking about state machines and how remarkably useful they are, and how frustrating they can be to implement. By the end of this episode we'll have decided that the solution to that frustration is to write a compiler that generates the code from a simple syntax.

The next few episodes will explore how to write that compiler; and how to use Finite State Machines to write that compiler.

These next few episodes are going to be fun, challenging, and important. You aren't going to want to miss them.