$> git checkout state
$> composer update
Intent
Allow an object to alter its behavior when its internal state changes. The object will appear to change its class.1
Applications
The state pattern is a glove pattern. When it fits right, it fits just right. In other words, you’ll know when you need it. You can use state pattern for modeling things that change behavior during the course of its lifetime.
Ever find yourself using some string variable named $type and a giant cluster of switch/case/if/else statements to determine which methods to call? The state pattern will clean up all those nasty conditions. A ...