O'Reilly logo

Head First Design Patterns by Eric Freeman, Elisabeth Robson, Bert Bates, Kathy Sierra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

image with no caption

But these manufacturers are gumball machine experts, not software developers, and they’ve asked for your help:

image with no caption

Cubicle Conversation

Anne: This diagram looks like a state diagram.

Joe: Right, each of ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required