PHP
  Home arrow PHP arrow Page 4 - Factoring Content Boxes with the Facto...
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 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
JMSL Numerical Library 
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

Factoring Content Boxes with the Factory Pattern in PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 4
    2007-07-09

    Table of Contents:
  • Factoring Content Boxes with the Factory Pattern in PHP 5
  • Factoring web page content boxes
  • Building different types of content boxes
  • Displaying web page content boxes via the factory pattern

  • 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


    Factoring Content Boxes with the Factory Pattern in PHP 5 - Displaying web page content boxes via the factory pattern


    (Page 4 of 4 )

    As I explained in the previous section, a good method for demonstrating how the factory class that I defined in the beginning of this tutorial can be used to display distinct types of content boxes is to develop a fully-functional example where a sample web page is constructed and the boxes are included in its main section.

    Based on this premise, below I coded a short script which performs these tasks.

    Please look at the following code sample:

    try{
       // create new web page object
       $webPage=new WebPage();
       // display web page header
       echo $webPage->createHeader();
       // create some content boxes
       $greyBox=ContentBoxFactory::createContentBox('grey','Title for
    grey box','This is the sample content for a grey box that has
    been created with the factory pattern.');
       $blueBox=ContentBoxFactory::createContentBox('blue','Title for
    blue box','This is the sample content for a blue box that has
    been created with the factory pattern.');
       $yellowBox=ContentBoxFactory::createContentBox('yellow','Title
    for yellow box','This is the sample content for a yellow box that
    has been created with the factory pattern.');
       // display content boxes
       echo $greyBox->display();
       echo $blueBox->display();
       echo $yellowBox->display();
       // display web page footer
       echo $webPage->createFooter();
    }
    catch(Exception $e){
       echo $e->getMessage();
       exit();

    It may be hard to believe, but the above script is all the source code required to display a sample web document that contains the three previously defined content boxes. In this case, I used the corresponding factory class to generate each of the content box objects, which are displayed on the web page via their "display()" method.

    As you can see, this is a fine demonstration of how to use the neat functionality provided by the factory pattern in a real world situation. So, do you want to put this helpful pattern to work? Go ahead and try developing your own examples!

    Final thoughts

    Sadly, we've come to the end of this series. In these three articles, I showed you with numerous examples how to implement the factory design pattern with PHP 5. Hopefully, this series will contribute to expand your existing background in pattern-based programming.

    See you in the next PHP tutorial!


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · In this final part of the series, the popular factory pattern is used to create...
       · Short and Simple! Thanks!However, I would like to point out that since all...
       · First off, I'd like to thank you for commenting on my PHP article. Now, with regard...
       · Thank you for commenting on my PHP article, as well as for all the useful sugestions...
     

       

    PHP ARTICLES

    - Paginating Database Records with the Code Ig...
    - HTTP Headers in Web Development
    - Project Management: Administration
    - Building a Database-Driven Application with ...
    - User Authentication for a Project Management...
    - Introduction to the CodeIgniter PHP Framework
    - Adding Users for a Project Management Applic...
    - Migrating Class Code for a MIME Email to PHP...
    - Login and Logout Authentication for a Projec...
    - Composing Messages in HTML for MIME Email wi...
    - Project Management: Authentication
    - A Better Way to Determine MIME Types for MIM...
    - Project Management Overview
    - Handling Attachments in MIME Email with PHP
    - Completing the Project Management Application





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway