PHP
  Home arrow PHP arrow The Basics of Using the Factory Pattern in PHP 5
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

The Basics of Using the Factory Pattern in PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 9
    2007-06-25


    Table of Contents:
  • The Basics of Using the Factory Pattern in PHP 5
  • Developing some basic factory classes
  • Defining some array processing classes
  • Testing the functionality of the factory pattern

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    The Basics of Using the Factory Pattern in PHP 5
    ( Page 1 of 4 )

    If you need to create multiple objects that belong to the same family, you probably want to use the factory pattern. This three-part series takes a close look at using the factory pattern in PHP.

    Introduction

    Many PHP developers with a solid background in pattern-based programming know that there are certain patterns that are more difficult to grasp than others. This is due mostly to the inherent diversity of this fascinating terrain, where purist concepts about software design merge flawlessly with simple, natural common sense.

    Indeed, design patterns present singularly interesting facets. They are conceived as proven solutions to specific programming-related issues, but at the same time, have a certain dose of improvisation, which makes them even more attractive. Logically, if you think carefully about this concept, you'll understand more clearly the meaning of this question: how many times did you find yourself applying a particular pattern without knowing what you were actually doing? Perhaps dozens, even hundreds of times.

    Nevertheless, the most important thing to notice here is that a concrete problem can be solved by implementing the logic of a particular pattern, which means that certain software development issues can be addressed in a more intuitive way than others. And definitely, the factory pattern is an excellent example of this situation, since many developers use it frequently, even if they're taking their first steps into the object-oriented programming arena.

    Admittedly, it's common to see during the development of a given PHP application that one or more classes are created with the purpose of returning a specific type of object to client code, where the object must conform to the specifications of a concrete environment. As you may have guessed, this is precisely the theoretical definition of the factory pattern.

    Summarizing, the factory pattern can be really useful when it comes to creating multiple objects that belong to the same family. In this three-part series I'm going to take a close look at it, and also demonstrate its remarkable functionality by showing you a decent variety of code samples, so you can start quickly including this pattern into your own PHP applications.

    With the preliminaries out of the way, now let's move on together and begin discovering how to apply the factory pattern with PHP. It's going to be an educational journey, believe me!



     
     
    >>> More PHP Articles          >>> More By Alejandro Gervasio
     

       

    PHP ARTICLES

    - Using Directory Iterators to Build Loader Ap...
    - Using the spl_autoload() Functions to Build ...
    - Working Out of the Object Context to Build L...
    - Using the _autoload() Magic Function to Buil...
    - The Destruct Magic Function in PHP 5
    - The Autoload Magic Function in PHP 5
    - Developing a Recursive Loading Class for Loa...
    - The Sleep and Wakeup Magic Functions in PHP 5
    - Using the Clone Magic Function in PHP 5
    - Including Files Recursively with Loader Appl...
    - The Call Magic Function in PHP 5
    - Designing a Captcha System with PHP and MySQL
    - Using Static Methods to Build Loader Apps in...
    - The Isset and Unset Magic Functions in PHP 5
    - Advanced PHP Form Input Validation to Check ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
    Stay green...Green IT