Several years ago I wrote a post, Why Are PHP Design Patterms Missing Pieces? I looked at a lot of PHP design patterns and found that several have major missing parts. In one of the earliest list of PHP design patterns on an IBM-sponsored site from 2006, for example, the Factory pattern is described and it has an example, but the Simple Factory (which was the actual pattern shown) is not the same as the Factory Method pattern that includes four participants: Product, Creator, Concrete Product and Concrete Creator. Generally, the “Creator” is used interchangeably with “Factory” and there seemed to be a lot of developers who make Simple Factory designs, but they only get an ‘honorable mention’ from the Freemans as a design pattern. (The Freemans refer to the Simple Factory as a programming idiom.)

PHP Gets No Respect!

I hate it when C# snobs or Java divas stick up their noses at PHP developers, but when you look at the design patterns attributed to The Gang of Four, these other languages have fully developed examples (the Freemans’ Head First Design Patterns, being first among them). However, we don’t have so many, and if you look at the examples online, you’ll see that many are missing parts. Rather than rage at the storm and what makes us PHP developers look like a collection of befuddled hackers, I’ve created a new column for the “Variation and Intent” table that lists all of the Participants—it’s sort of a Parts List for design patterns. Click the Play button to see the new table: The italicized participants are abstract classes or interfaces. Often the examples in PHP may be perfectly good examples of OOP programming, but they’re not design patterns nor do they offer the advantages of design patterns. Others, like the table pictured with a missing leg, can set up the developer for problems somewhere in the program. So, if you have a design pattern with a missing part, ask yourself,

What could possibly go wrong?

Don’t Forget the Client!

The Client object is listed as a direct or implied participant in most of the design patterns. It is further mentioned in the collaboration of several others. In the original Gang of Four tome, you will see several class diagrams with the Client “ghosted” (light gray) indicating an implied role. However, in nearly half of the patterns, the Client is an integral part of the pattern. You’d be surprised how many developers leave them out or (worse) refer to them as “main” (a leftover from C++). In any event, I’ve included all of the Client participants, including those implied. Also, you will see where the Client is mentioned in collaboration with the main participants.

Use the Participant Column as a Check List

The next time you go looking for a PHP design pattern to use, check to make sure it has all of its parts. The original collection released through the IBM site in 2006 fostered legions of incomplete PHP design patterns. These patterns have persisted over the years, and the only way to get back on the right track is to look at the original Gang of Four participants. Now that you have a parts list, you can check for yourself.