Chapter 10. The State Pattern: The State of Things
A little-known fact: the Strategy and State Patterns were twins separated at birth. As you know, the Strategy Pattern went on to create a wildly successful business around interchangeable algorithms. State, however, took the perhaps more noble path of helping objects to control their behavior by changing their internal state. He’s often overheard telling his object clients, “Just repeat after me: I’m good enough, I’m smart enough, and doggonit...”
Java toasters are so ’90s. Today people are building Java into real devices, like gumball machines. That’s right, gumball machines have gone high tech; the major manufacturers have found that by putting CPUs into their machines, they can increase sales, monitor inventory over the network and measure customer satisfaction more accurately.
At least that’s their story – we think they just got bored with the circa 1800’s technology and needed to find a way to make their jobs more exciting.
But these manufacturers are gumball machine experts, not software developers, and they’ve asked for your help:
Judy: This diagram looks like a state diagram.
Joe: Right, each of ...