PHP
  Home arrow PHP arrow Page 3 - The Basics of Abstract Factory Classes...
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 Basics of Abstract Factory Classes in PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 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:
      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 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


       · Over this first installment of the series, you'll learn the foundations of the...
       · I'm not quite sure what those abstract classes are for since they aren't called in...
       · Thank you for commenting on my PHP article. With reference to your question,...
     

       

    PHP ARTICLES

    - Using Aliases and the Autoload Function with...
    - 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
    - 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
    - Sub Classing Exceptions in PHP 5
    - Building a Content Management System with Co...
    - Filters and Login Systems for Web Applicatio...





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