State Machines

In the section above, we converted a single type with flags into a set of separate types, each designed for a specific workflow stage.

This is the second time we’ve done this. In the EmailAddress example discussed, we converted a design with a flag into a design with two choices, one for each state: “Unverified” and “Verified.”

These kinds of situations are extremely common in business modeling scenarios, so let’s pause and look at using “states” as a general domain modeling tool. In a typical model, a document or record can be in one or more states, with paths from one state to another (“transitions”) triggered by commands of some kind as shown in the figure. This is known as a state machine.

Now you might be familiar with complex ...

Get Domain Modeling Made Functional now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.