PHP
  Home arrow PHP arrow Page 4 - Implementing the Stage Pattern 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

Implementing the Stage Pattern in PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 4
    2007-04-18


    Table of Contents:
  • Implementing the Stage Pattern in PHP 5
  • Creating the programmatic model of the state pattern
  • Changing the behavior of a target class
  • Seeing the stage 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


    Implementing the Stage Pattern in PHP 5 - Seeing the stage pattern in action
    ( Page 4 of 4 )

    As you certainly recall from the previous section, I thought that the best way to understand the functionality provided by the stage pattern is by simply setting up a concrete example where the pair of classes that you learned earlier are put to work in tandem.

    Since I consider this a good approach to demonstrate how the pattern in question works, in the next few lines I coded a short script, which shows how a contextual div object is capable of modifying the behavior of a given DIV element, in this case by changing the value of its “overflow” CSS property.

    As I explained in the prior section, the aforementioned CSS property will be modified according to the length of the contents included into the target DIV, certainly a condition that is in evidence by the below example.

    That being said, please take a look at the following code listing:

    try{
       // create new 'Div' object
       $div=new Div();
       // set Div properties
       $div->setData('This is a sample string that will be included
    into the DIV.');
       $div->setId('newid');
       $div->setClass('newclass');
       // create new 'DivContext' object
       $divContext=new DivContext($div);
       // display DIV element (its overflow property has a value of
    'hidden')
       echo $divContext->getDivHTML();
       // set new data for Div element
       $div->setData('This is a sample string that will be included
    into the DIV, but in this case the behavior of the DIV object
    will change since the length of this data is larger than 64
    characters.');
       // display DIV element (its overflow property has a value of
    'scroll')
       echo $divContext->getDivHTML();
    }
    catch(Exception $e){
       echo $e->getMessage();
       exit();
    }

    As demonstrated above, the contextual div object is capable of modifying the value of the “overflow” CSS property that belongs to the target DIV, in this way changing its behavior according to the requirements of a given context.

    Now that you grasped the logic that stand behinds the stage pattern, I encourage you to develop your own examples, so you can acquire a more solid background on how this pattern can be used in concrete situations.

    Final thoughts

    Sadly, we’ve come to the end of this first article of the series. As you saw previously, the stage pattern can be useful in those cases where the context of a particular PHP application is going to change very frequently.

    However, if you believe that all the hands-on examples shown in this tutorial are not enough material, I’ve got good news to you. In the last part of the series I’m going to show you how to implement the stage pattern to generate “screen” and printer-friendly versions for a bunch of web documents.

    Now that you’ve been warned, are you going to miss it? I hope not!



     
     
    >>> 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 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek