Datasheet

Part I: Getting Acquainted with Design Patterns and PHP
6
Even more detailed and closer to the root patterns are examples found in your favorite PEAR or other
framework libraries. For example, using PEAR DB is an example of putting a Design Pattern into use
(notably the factory method). The Zend Framework also uses various different patterns such as the
Singleton and the Adapter patterns.
The Common Parts of a Design Pattern
The Gang of Four pioneered a documentation standard for describing Design Patterns. They used this in
their book for each of the patterns that they mentioned. Authors after them have copied this exact format
and continued to propagate this form of documentation. I was a little bit less verbose with you because
I felt a lot of the sections either reiterated the sections above them or were just there for structure s sake.
The introduction to this book mentions the four main parts of each pattern s documentation: the name, the
problem and solution, the Universal Modeling Language (UML) diagram, and the code example.
The Name
The name is actually more important in Design Patterns than you may initially guess it is. Proper
descriptive naming conventions can go a long way toward explaining the behavior and relationship of
the pattern to the project and other patterns.
In the example for this chapter, you saw how Jason mentioned to Steve that he was going to rewrite a
portion of the payment - processing system. Since Steve was the senior programmer, he may not have
necessarily agreed with the approach that Jason was using, but he certainly could have suggested some
patterns to be used in that rewrite s architecture. This way, the entire team would both be familiar with
the underlying concepts of the payment system, with Jason specializing in the exact implementation.
Problem and Solution
As mentioned previously, Design Patterns are what emerge from solving the same problem with the
same general solution. This section of the description covers the main problem or problems in your
project and then shows how this particular Design Pattern is one of the better solutions.
As you may have noticed, I didn t use the phrase the best solution because no one can say this
definitively. Even if you find what you believe is the best Design Pattern for a particular problem, you ’ re
going to have to apply a certain amount of tweaking to it in order for it to fit perfectly into your project.
UML Diagram
The UML diagram will show the general structure of the pattern. In some cases, it may be necessary to
generate more than one diagram to show additional implementations of the pattern or to illustrate a
complex concept in easier - to - understand segments.
What is UML?
Unified Modeling Language ( UML ) diagrams should be a staple in your programming
arsenal. UML is a standard way to diagram programming actions, objects and use
cases. This helps communicate your design when building complex software in PHP.
For a quick refresher on UML, visit the
http://Wikipedia.org/wiki/Unified_
Modeling_Language page on Wikipedia
.
c01.indd 6c01.indd 6 7/17/09 12:17:45 PM7/17/09 12:17:45 PM