PHP
  Home arrow PHP arrow Implementing Factory Methods 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 
iPad news and developer info.
Ads by affinity 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
VPS Hosting 
Forums Sitemap 
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? 
Google.com  
PHP

Implementing Factory Methods in PHP 5


By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 3
    2009-11-24


    Table of Contents:
  • Implementing Factory Methods in PHP 5
  • The simplest object constructor
  • Defining factory methods
  • Factoring web form element objects

  • 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


    Summary: If you’ve ever developed desktop applications using mature object-oriented languages like C++ and Java, then it’s possible that you’ve found yourself saying a few funny phrases such as “I need to implement a factory method within this class,” or in the worst case: “this class needs to implement a factory method, but I don’t have a single clue about how to do that.” Surprisingly, you can implement these factory methods pretty quickly and easily in PHP 5, as this six-part series will show you.

    Implementing Factory Methods in PHP 5
    (Page 1 of 4 )

    To be honest, I grappled with factory methods in Java myself, but in the end I learned not only how to quickly build factory methods in Java classes, but how to implement those methods in PHP as well.

    While it's undeniable that PHP is easier to learn than Java, many PHP developers with long experience in developing procedural programs may find it hard to grasp the foundations of the object-oriented paradigm, to say nothing of the implementation of design patterns that involve the use of objects, such as Singletons or the aforementioned Factory.

    Fortunately, building factory methods in PHP is a simple process, which became even simpler with the release of PHP 5. But what is a factory method? In a nutshell, a factory method is a method that fabricates things and returns them when possible to client code.

    In most cases, these things are objects, but they don't have to be. However, by far the most important facet of factory methods is their ability to create objects, which means that they play a relevant role when building object-oriented web programs, and therefore deserve a closer look.

    So, given the importance of factory methods to developing web applications, in this group of tutorials I’m going to show how to implement this kind of method in PHP 5. I'll start with some basic code samples, and then, with the key concepts already digested, I’ll go into more complex examples that will combine the use of Singletons and static methods.

    Now, it’s time to start learning how to define a few simple factory methods with PHP 5. It’s going to be an instructive journey, trust me!



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

       

    PHP ARTICLES

    - PHP Excel Customizations: Working with Formu...
    - MVC and the Zend Framework
    - PHP: Rendering Web Pages Using the Composite...
    - PHP: Creating Dynamic Web Pages with the Com...
    - Secure Encrypting and Decrypting for Your PH...
    - PHP: Creating Single View Objects with the C...
    - PHP: View Object Collections and the Composi...
    - Securing Your PHP Website
    - Determine Link Relevance and Unique Class C ...
    - PHP Composite View Design Pattern: Introduci...
    - Facebook PHP API Applications: A Second Look
    - Secure PHP Programming
    - Facebook PHP API Applications: Basic Introdu...
    - SOAP Servers and Web Services
    - Using XPath, SOAP, and More with Web Services


    Code Analysis Tools
    Enterprise code analysis tools that deliver quality and reliable code



    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 8 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek