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...”
Jawva Breakers
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.
Note
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:


Cubicle Conversation
Judy: This diagram looks like a state diagram.
Joe: Right, each of ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access