Datasheet

Part I: Getting Acquainted with Design Patterns and PHP
8
Design Patterns are Maintainable But Not Always
Most Efficient
Design patterns don t always lend themselves to the greatest efficiency and speed in applications either.
The goal of a Design Pattern is to help you design a solution in an easily repeatable and reusable way.
This means the Pattern may not be specifically tailored to your situation but will have greater code
maintainability and understandability.
Design Patterns are a Vehicle, Not a Refactoring End
A particular supervisor of mine just finished reading a book by Joshua Kerievsky and came to me with
his newly acquired knowledge. He told me that we need to refactor our code base to use all Design
Patterns. We had a discussion about what refactoring really meant, especially in our context.
While respecting Kerievsky and not disagreeing, I do feel that a greater distinction should be maintained
when coupling Design Patterns to refactoring. Refactoring approaches both creating a more efficient
code base and improving the maintainability and clarity of the code. Design Patterns are a great vehicle
for your refactoring approach, but shouldn t be the destination. While I m in favor of starting a project
with a highly detailed set of Design Pattern architecture specs, I don t want to force something into a
pattern for patterns sake. Imagine if the first rock bands in existence threw a piano into the mix just
because everyone else in music was doing it, and they thought they had to. You wouldn t have that
classic guitar - driven rock music that we ve come to love!
Design Pattern Demonstration
Most examples of Design Patterns historically have been very sparse and theoretical so as not to have the
reader confuse the core concepts with language - agnostic features. Readers who have studied Design
Patterns, or even Object Oriented Programming before will be very familiar with the ever - present
square, circle, and oval object examples.
The debate rages on about Design Pattern books using simple objects like squares or people in their
examples. Purists say you should detail the Design Pattern concepts and practice and give the
simplest examples possible so as not to distract from the actual implementation of the pattern.
(These are the people that hated story problems in math class because of all the extra information!) In my
experience, self - taught PHP programmers prefer to see more thorough examples of the concept in code
form. (They probably learned a lot by copy and paste coding when they first started.)
The Design Patterns in this book do contain small to medium - sized examples of PHP code to
demonstrate the pattern. This dual - phased approach combines the actual conceptual explanation of the
pattern for those who need that particular structure with the example - based pattern demonstration for
those who are more hands - on learners.
The reference pages of this book will be more satisfying to the purists, while the case study section at the
end will satisfy the code - example - hungry readers. For more information on the references pages, skip to
the next section to see how they will be laid out.
c01.indd 8c01.indd 8 7/17/09 12:17:46 PM7/17/09 12:17:46 PM