Chapter 10. The State Pattern: The State of Things

image with no caption

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:

image with no caption
image with no caption

Cubicle Conversation

Judy: This diagram looks like a state diagram.

Joe: Right, each of ...

Get Head First Design Patterns now with O’Reilly online learning.

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