PHP
  Home arrow PHP arrow Page 3 - The Basics of Abstract Factory Classes 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? 
Google.com  
PHP

The Basics of Abstract Factory Classes in PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 8
    2007-01-24


    Table of Contents:
  • The Basics of Abstract Factory Classes in PHP 5
  • Introducing the abstract factory pattern: defining an abstract web page element factory
  • Creating small and large DIV objects
  • Seeing the abstract factory pattern in action

  • 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 Abstract Factory Classes in PHP 5 - Creating small and large DIV objects
    ( Page 3 of 4 )

    After defining all the concrete factory classes that you learned in the previous section, the next step consists simply of creating a new set of classes that logically display small and large DIV elements. Of course, the pertinent definitions for these brand new classes are easy to follow, and are listed below. So, have a look at them, please:

    // define abstract 'DivElement' class
    abstract class DivElement{
       abstract function display();
    }
    // define concrete 'SmallWhiteDivElement' class
    class SmallWhiteDivElement extends DivElement{
       private $style='width: 100px; background: #fff; border: 1px solid #999;';
       private $content='This is the content of the small DIV element';
       public function display(){
         return '<div style="'.$this->style.'">'.$this-
    >content.'</div>';                      
       }
    }
    // define concrete 'SmallBlackDivElement' class
    class SmallBlackDivElement extends DivElement{
       private $style='width: 100px; background: #000; color: #fff; border: 1px solid #999;';
       private $content='This is the content of the small DIV element';
       public function display(){
         return '<div style="'.$this->style.'">'.$this-
    >content.'</div>';                      
       }
    }
    // define concrete 'LargeWhiteDivElement' class
    class LargeWhiteDivElement extends DivElement{
       private $style='width: 500px; background: #fff; border: 1px solid #999;';
       private $content='This is the content of the large DIV element';
       public function display(){
         return '<div style="'.$this->style.'">'.$this-
    >content.'</div>';                      
       }
    }
    // define concrete 'LargeBlackDivElement' class
    class LargeBlackDivElement extends DivElement{
       private $style='width: 500px; background: #000; color: #fff; border: 1px solid #999;';
       private $content='This is the content of the large DIV element';
       public function display(){
         return '<div style="'.$this->style.'">'.$this-
    >content.'</div>';                      
       }
    }

    As illustrated above, the four previous classes are responsible for returning (to calling code) the correct (X)HTML markup that renders a specific DIV element. In the first two cases, the aforementioned classes will display small DIVs, while on the other occasions, only large DIVs will be created. Pretty simple, right?

    All right, now you have learned how to create an abstract factory class which is capable of indicating what DIV objects should be spawned by the respective concrete factories, in accordance with their corresponding contexts. Nevertheless, I believe firmly that you'll understand the functionality of all these classes more easily if I set up an illustrative example where they can be put to work conjunctly.

    Taking this fact into account, I suggest that you go ahead and read the next few lines, since you're just about to see the real power of the abstract factory pattern!



     
     
    >>> 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