PHP
  Home arrow PHP arrow Page 2 - Using Abstract Factory Classes in PHP 5 to Work with Online Forms
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? 
Google.com  
PHP

Using Abstract Factory Classes in PHP 5 to Work with Online Forms
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 9
    2007-02-07


    Table of Contents:
  • Using Abstract Factory Classes in PHP 5 to Work with Online Forms
  • Defining an abstract form element factory class
  • Creating context-driven form objects
  • Understanding how the abstract factory pattern works

  • 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


    Using Abstract Factory Classes in PHP 5 to Work with Online Forms - Defining an abstract form element factory class
    ( Page 2 of 4 )

    As I expressed in the introduction that you just read, I plan to define a group of concrete form element factories. These factories will be responsible for creating the correct types of form objects according to the context where these objects will be used.

    Of course, before I proceed to defining this set of concrete factory classes, I must create an abstract form element factory class, in this way implementing the schema dictated by the referenced pattern.

    As you'll see in a brief moment, the abstract factory class that I'm going to define will set up a generic interface for building simple input and check boxes, as well as radio buttons. Nonetheless, after creating the abstract factory class, I'm going to derive three subclasses from it. These classes will come in handy for spawning "required" and "non-required" form objects, therefore establishing the respective contexts where these objects will be utilized.

    Okay, having said that, here are the corresponding signatures for the abstract and concrete factories classes that I discussed previously. Please take some time to examine their respective signatures:

    // define abstract 'AbstractFormElementFactory' class
    abstract class AbstractFormElementFactory{
      
    abstract public function createInputBox();
      
    abstract public function createRadioButton();
      
    abstract public function createCheckBox();
    }

    // define concrete 'RequiredInputBoxFactory' class
    class RequiredFormElementFactory extends AbstractFormElementFactory{
      
    private $context='required';
      
    public function createInputBox(){
        
    return new RequiredInputBox();
      
    }
      
    public function createRadioButton(){
        
    return new RequiredRadioButton();
      
    }
      
    public function createCheckBox(){
        
    return new RequiredCheckBox();
      
    }
    }

    // define concrete 'NormalInputBoxFactory' class
    class NormalFormElementFactory extends AbstractFormElementFactory{
      
    private $content='normal';
      
    public function createInputBox(){
        
    return new NormalInputBox();
      
    }
      
    public function createRadioButton(){
        
    return new NormalRadioButton();
      
    }
      
    public function createCheckBox(){
        
    return new NormalCheckBox();
      
    }
    }

    As illustrated above, the first abstract factory class defines a generic interface. This interface is convenient for creating web form objects, including check and input boxes, as well as radio buttons. Nevertheless, if you pay attention to the pertinent concrete factories, you'll see that each one of them defines the context where the form objects will be utilized.

    In this case in particular, the first factory will be responsible for creating web form objects that only work in a "required" context, while the second class will be capable of returning to client code, form objects that are functional in a "normal" (non-required) context. So far, the way that all the previous factory classes were defined is by far simple to understand, right?

    Now, after having outlined generally the respective behaviors for each of the factory classes defined previously, it's time to show the corresponding definitions for all the form element classes. These are tasked with generating input and check boxes, and radio buttons as well, in consonance with a predefined context.

    As usual, to see how all these brand new classes will be created, click on the link shown below and keep reading.



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

       

    PHP ARTICLES

    - Implementing Factory Methods in PHP 5
    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL





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