AL Part I TE D MA TE RI Getting Acquainted with Design Patterns and PHP GH Chapter 1: Understanding Design Patterns CO PY RI Chapter 2: Using Tools Already In Your Arsenal
Understanding Design Patterns Usually when I pick up a book and see a chapter longer than five pages about a topic that I’m not the most familiar with, I tend to get scared. More than five pages may see me dropping the book and running away, flailing my arms and shouting about how tough these computers are! While this chapter may be longer than five pages, don’t be discouraged. The term Design Pattern is just a fancy name for something that is not all that complex.
Part I: Getting Acquainted with Design Patterns and PHP The news comes down from the vice president that the corporate site needs to allow customers to process their payments after they have completed a successful, secure user log in. Additionally, the system needs to show how many times the customer has called in to the call center. Finally, it needs to show an audit log of every change the call center has made to the customer ’s account.
Chapter 1: Understanding Design Patterns It was once said that every single piece of music that could be written already has been. Now, new music creation is just the rearranging of those particular sets of notes to different tempos and speeds. It’s the same with general software development, barring a few major groundbreaking exceptions. The same problems come up repeatedly and require common solutions. This is exactly what Design Patterns are: reusable solutions for these common problems.
Part I: Getting Acquainted with Design Patterns and PHP 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.
Chapter 1: Understanding Design Patterns 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.
Part I: Getting Acquainted with Design Patterns and PHP 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.
Chapter 1: Understanding Design Patterns Why Use Design Patterns in PHP? PHP has a very easy beginner ’s learning curve with the backing of an enterprise-ready engine. Chances are that you ventured into PHP by inserting a few lines of code into an existing HTML document. Simply change the extension from .html to .php, add your quick snippet of code, deploy it to a PHP server, and you’re a bona-fide PHP programmer.