December 2016
Beginner to intermediate
238 pages
6h 10m
English
© Kelt Dockins 2017
Kelt Dockins, Design Patterns in PHP and Laravel, 10.1007/978-1-4842-2451-9_23
Kelt Dockins1
(1)Dolph, Arkansas, USA
$> git checkout state$> composer update
Allow an object to alter its behavior when its internal state changes. The object will appear to change its class.1
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 ...
Read now
Unlock full access