SunQuest
 
       PHP
  Home arrow PHP arrow Implementing the Stage Pattern in PHP ...
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 
Actuate Whitepapers 
VeriSign Whitepapers 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
IBM developerWorks
 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

Implementing the Stage Pattern in PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 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:
      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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Implementing the Stage Pattern in PHP 5


    (Page 1 of 4 )

    Updating modules of a web application can be quite a chore, especially when classes are involved. Wouldn't it be easier if there were a class that could update itself depending on its context? Fortunately there is. It's called the Stage pattern. This is the first part of a two-part series that introduces you to that pattern and its uses.

    Introduction

    It’s quite probable that during your life as a PHP developer, you have found yourself updating specific modules of a given web application (or in the worst case, the entire application), since the context where it was originally conceived to work has changed noticeably.

    Naturally, if this situation sounds familiar to you, then you’ll know that updating certain parts of an application can be an annoying, time-consuming process. it can be even worse if you have to deal with other issues apart from the ones related to coding, such as suiting deadlines, solving “creative” differences between members of the same development team, and so forth.

    Thus, considering all the possible problems that can emerge when a particular PHP application must be updated, you try to write code that is highly maintainable and easy to update. However, if I translate the aforementioned scenario to the terrain of object-oriented programming, sometimes it happens that one or more PHP classes need to be updated according to the modifications introduced into the context where they were initially designed to work.

    From a developer’s point of view, this updating process can be difficult, particularly if the application that needs to be modified is comprised of a considerable number of interrelated classes. Therefore, the question that comes up here is: is there any programmatic mechanism that allows you to create a class that changes the way it works, according to the variations incorporated into its environment?

    Fortunately, the answer to the previous question is an emphatic yes! In the huge area of pattern-based programming, there’s one pattern called “Stage” that provides developers with a handy mechanism for building a class that’s capable of modifying its behavior in response to the changes introduced into its environment. Indeed, this sounds pretty interesting, right?

    Nevertheless, at least at first glance, the definition of the “Stage” pattern seems hard to grasp, which implies that the pattern in question has to be addressed from a practical point of view. In doing so, you’ll have a much better idea of how it works, and eventually how it can be applied in concrete cases.

    Therefore, assuming that the stage pattern has already caught your attention, over the course of this two-part series, I’m going to introduce its key concepts, and logically show you how to implement it with copious code samples.

    At the end of this series, you should be equipped with a decent background in how to include the stage pattern in your own PHP applications, aside from expanding your overall skills in pattern-based programming. So, are you ready to dive deeper into the implementation of this handy pattern? Let’s begin now!

    More PHP Articles
    More By Alejandro Gervasio


       · If you’re interested on creating a class that changes its behavior in response to...
       · The title of this article uses "Stage Pattern", however in the article body it...
       · Thank you for pointing me out that error in the article. It was my mistake, and you...
       · Thank you for pointing out that error to me. Actually, the correct name of the...
       · HI, Is there a way in which this can be done using php4? I don't know all the...
       · Thank you for commenting on my PHP article. Now with referene to your question, of...
     

       

    PHP ARTICLES

    - Viewing and Editing Tasks for a Project Mana...
    - More on Private Methods with PHP 5 Member Vi...
    - Adding Tasks to a Project Management Applica...
    - Utilizing Private Methods with PHP 5 and Mem...
    - Making Changes in a Project Management Appli...
    - Defining Public and Protected Methods with M...
    - HTML for a Project Management Application
    - Using Subclasses and Accessors with Member V...
    - Implementing Internet Protocols with PHP
    - Project Management: The Application
    - Working with Private Properties to Protect P...
    - Protecting PHP 5 Class Data with Member Visi...
    - Setting Up a Web-based Image Hosting Service
    - Comparing Files and Databases with PHP Bench...
    - Setting Up a Web-Based Image Gallery





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