PHP
  Home arrow PHP arrow The Singleton and Factory Patterns in ...
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
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 Singleton and Factory Patterns in PHP: a rendering-capable factory class
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 10
    2005-11-16

    Table of Contents:
  • The Singleton and Factory Patterns in PHP: a rendering-capable factory class
  • The Factory pattern in a real application: a quick look at the “formElementFactory” class
  • A smarter factory: applying Polymorphism within the “formElementFactory” class
  • Polishing the Page

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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 Singleton and Factory Patterns in PHP: a rendering-capable factory class


    (Page 1 of 4 )

    In this third part of the series, I will explain how to implement the Factory pattern in conjunction with the polymorphic characteristics of form objects. This will boost the functionality of the factory class by simplifying the process for rendering form elements.

    Introduction

    Welcome to the third part of the series “The Singleton and Factory Patterns in PHP.” As you probably remember, in the second part of this series, I applied the functionality of the Factory pattern to taking the process of regular form generation from an object-oriented point of view, branching to a different direction from the traditional way for coding web forms.

    Essentially, the form generation process can be divided into three key categories: element class definition, form element factory class definition, and finally visual presentation. As you might guess, the first one refers to the stage at which all of the form elements are structured as individual classes, the second implies specifically the definition of the required form factory itself, while the third stage is tasked with rendering each form element according to the specific needs within the program.

    So far, I’ve demonstrated a basic implementation of the abstract “formElementFactory” class, which is responsible for creating form element objects, by separating object instantiation from the rest of the application code.

    As I mentioned previously in the second part of the series, there are several features that must be added to the logic of the form application, in order to get a more functional version of it, by satisfying several requirements often present in real environments.

    Certainly, the first issue to be properly addressed is the rather ineffective implementation of Polymorphism for rendering form elements. The second issue is  the lack of control in the overall presentational layout of the form.

    For most of these problems to be efficiently solved, we need to apply some refactoring to the form element factory. We do this by adding the capability to take advantage of the polymorphic features exposed by each form element object, as well as implementing a basic control on the visual presentation for every element.

    In this part of the series, I shall provide an overview of the solutions for tackling the above conflicting topics, while maintaining a strong practical approach in the use of design patterns.

    So, it’s time to learn more about applying design patterns to object-oriented forms. Let’s get started.

    More PHP Articles
    More By Alejandro Gervasio


       · The third installment of the series goes through the application of Polimorphism to...
       · While you do explain things very simply (and I thank you for that) you do take...
     

       

    PHP ARTICLES

    - Authentication Scripts for a User Management...
    - Utilizing the Use Keyword for Namespaces in ...
    - Building a User Management Application
    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Database Security: Guarding Against SQL Inje...
    - Building a Modular Exception Class in PHP 5
    - Database and Password Security for Web Appli...
    - Handling MySQL Data Set Failures in PHP 5
    - Building Site Registration for Web Applicati...
    - Intercepting Customized Exceptions in PHP 5
    - Securing Your Web Application Against Attacks
    - Sub Classing Exceptions in PHP 5
    - Authentication for Web Application Security





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