There are few people this side of Harry Fuecks who have rode the php design patterns money train as much as I have. In fact, programming patterns have been very good to me: they’ve provided trips to exotic locales, paid for my conference admission, impressed all the hot women…
Well maybe not that last one.
But Alejandro’s recent spate of GoF patterns on DevShed, besides being a blast from the past, made me realize that practicality hangs over my Pattern Bubble like the Sword of Damocles, pointedly showing just how oppressive programming design patterns in PHP are.
Time for a new rule:
“With few exceptions, by the time you deduced what a pattern is from its clever name, you could have just coded it.”
—Terry Chay, 2007
and my original inspiration:
“PHP isn’t Java. Deal.”
—Terry Chay, 2003
[The Flyweight makes an appearance after the jump]
Yep, I’m doing a pattern sell-off faster than today’s stock market drop and this pattern whore has checked into rehab (and this time I’m not going to to come out demanding someone shave my head.)
The Flyweight
You know what really grinds my gears? When PHP articles on design patterns, after quoting the inevitably opaque definition of the pattern, give examples that have no practical use in web development: Flyweight pattern, anyone?
PHP developers would be better served being taught the very similar Singleton Registry pattern with the example being able to reuse database connection objects.
As for a valid use of Flyweight in PHP, I’m scratching my head. I guess if your PHP site had a User object with some nasty-assed property containing an object inside whose total data set is very small (like maybe they had the user’s TimeZone attached to it as an object) and in the unlikely even that the PHP script might load 100,000 of these User objects, then Flyweight would reduce the memory footprint by reusing the maybe 40 or so TimeZone objects.
But returning the same three input html elements? Puh-leez. Is this shit for real? I thought PHP-side form generator and validator classes were so 2005.
(And to skip picking on poor Alejandro for a second, check out this example. What’s with this obsession with three anyway?)
Women and design patterns
I thought I’d bookend this article by talking about hot women again…
“There is no way the flyweight pattern is going to stop a pretty girl from accessorizing.”
—Terry Chay, 2007
Reuse and share the same object my ass! See, now if that wasn’t so geeky, I could use it on a hot girl at a post-conference pub crawl to get a laugh.
Or a slap in the face.













