Chapter 7. Patterns

Hacks 67–78: Introduction

In 1994, Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides published Design Patterns (Addison Wesley). The book quickly became a computer science classic because of its useful material, and it even pioneered a new metalanguage in the engineering and architecture communities. The book’s underlying principle, which was to provide a set of patterns of object structure and intra-object structure, was adopted from building architecture and was smoothly applied to programming.

The set of 40 patterns presented in the book were gleaned from years of experience. Each pattern was presented in a language-neutral form, and most could be applied to any development environment.


A few of the patterns, such as the Iterator pattern, were specifically developed to make up for shortcomings in a language (in the case of Iterator, that language was C++). PHP implements the Iterator pattern inherently through the foreach method.

Patterns have been notoriously underused in PHP. Not until the advent of PHP 5 were the language and environment taken seriously in the enterprise software development community. Now, with a robust object model, solid IDEs, and wide developer adoption, the enterprise community is starting to notice PHP. Several books on PHP have recently covered the use of patterns in the language, and I think it’s worth visiting them here.

In this book, I chose to use the original Design Patterns book as reference. I chose a subset of patterns ...

Get PHP Hacks now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.