...

/

Implementing State Machines With the State Pattern

Implementing State Machines With the State Pattern

In this lesson, we will explain the implementation State pattern in the C language.

State Pattern

According to Design Patterns "the State pattern models state-specific behavior, whereas the table-driven approach focuses on defining state transitions". When applying the State pattern to our example, the structure in Illustration 1 emerges.

This diagram looks like an object-oriented solution. However, we will not emulate inheritance in C. Before developing a concrete implementation, let’s explain the involved participants.

  • DigitalStopWatch:
    Design Patterns defines DigitalStopWatch as the context. The context has a reference to one of our concrete states, without knowing exactly which one. It is the context that
...