Datasheet

Chapter 1: Understanding Design Patterns
7
You may find that the building blocks for generating your own UML diagrams for your project can be
loosely based on these generic pattern diagrams. Of course, your method names, class names, and
attributes will vary and be more complex than those in the example.
The Code Example
Hands - on PHP programmers are finally rejoicing: the code examples. These are going to be relatively
simple examples of the Design Pattern concept put into PHP code. The bonus here in having a PHP -
based Design Patterns book is that you don t necessarily need to know another language to see an
example of this pattern. (Other books focusing on Enterprise Design Patterns have used Java or C
examples, somewhat taking away the effectiveness of the example to a sole - language programmer.)
I continue to reiterate: the code examples are simply that. They are not meant to be plug and play. They
may not contain error logging or handling, auditing, or wholly secure programming techniques. This is
not to say that I don t appreciate high - quality, secure programming (previous teammate programmers of
mine can confirm that I m a stickler for details), but it would distract from the main concept that I ’ m
trying to explain.
What Design Patterns Are Not
It s important to rein in the explanation of Design Patterns by also talking about what they don ’ t
encompass. Up until now, you may have noticed that I ve created a pretty large umbrella of coverage for
the Design Pattern definition.
Design Patterns Are Not Plug and Play
If you re expecting to flip to the Design Pattern pages of this book and see full examples that you can
quickly copy and paste for your next project, you will be sadly disappointed. Design Patterns are not just
a simple plug and play solution to your programming project.
Design Patterns are not the actual implementation or even the algorithm for solving the problem. For
example, you may create a design such that every house you construct has windows in the south to let in
more heat and light. You are not actually doing the constructing with exact measurements and locations
of the windows. You just hand over your design to the builder (programmer in our case), and they
implement it.
Another analogous way to view Design Patterns is to compare them to musical notes on a scale. You
may know all the notes in a minor scale, but playing them exactly in order and in the same tempo does
not make an enjoyable song. You can t open up a scale book, grab the scale, play it on guitar, and expect
everyone to think you re an amazing song writer. It would be quite boring and wouldn t solve the
problem your music is made for: to demonstrate a specific set of emotions via art. In this way, Design
Patterns are like those scales in the book. While they are the building blocks of a great solo, it is up to
you to apply them, tweak them, and create a great song.
c01.indd 7c01.indd 7 7/17/09 12:17:45 PM7/17/09 12:17:45 PM