PHP
  Home arrow PHP arrow Page 4 - Introducing Bridge Classes with 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

Introducing Bridge Classes with PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 7
    2007-01-03


    Table of Contents:
  • Introducing Bridge Classes with PHP 5
  • Introducing the basics of the bridge pattern
  • Implementing the bridge pattern’s core logic
  • Implementing the logic of a bridge class in a different hierarchy level
  • Seeing the bridge 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


    Introducing Bridge Classes with PHP 5 - Implementing the logic of a bridge class in a different hierarchy level
    ( Page 4 of 5 )

    In accordance with the concepts that you learned in the previous section, the “BridgeObjectSaver” class uses others to save target objects either to text files, cookies or arrays. Having at our disposal this handy programmatic structure, the logic that drives the bridge pattern is now easy to follow.

    As I stated before, the “BridgeObjectSaver” class resides on a different hierarchy level, since its logic is implemented by other objects, in this case called “ObjectToArray,” “ObjectToFile” and “ObjectToCookie” respectively. Now, do you realize how the pattern in question works? I bet you do!

    All right, having explained how the previous bridge class does its business, I’d like you to focus your attention on the signature for the following “bridged” classes that were discussed before. They’re defined as follows:

    //define 'ObjectToArraySaver' class class ObjectToArraySaver{ private $targetArray=array(); // implement concretely the logic of 'save()' method public function save($messageObj){ $this->targetArray['messageobj']=$messageObj; } } // define 'ObjectToFileSaver' class class ObjectToFileSaver{ private $targetFile='default_file.txt'; // implement concretely the logic of 'save()' method public function save($messageObj){ if(!$fp=fopen($this->targetFile,'w')){ throw new Exception('Error opening target
    file');               } if(!fwrite($fp,serialize($messageObj))){ throw new Exception('Error writing data to
    target file');      } fclose($fp); } } // define 'ObjectToCookieSaver' class class ObjectToCookieSaver{ private $targetCookie='targetCookie'; // implement concretely the logic of 'save()' method public function save($messageObj){ setcookie($this->targetCookie,serialize($messageObj),
    time()+7200); } }

    As you can see, the three classes shown above now implement concretely the logic defined by “BridgeObjectSaver.” In this case in particular, each one of the previous classes exposes a “save()” method to save target objects to different locations, including text files, arrays and cookies. Quite handy, right?

    Okay, at this point I’m quite sure that you grasped correctly the approach used for implementing the bridge pattern with PHP 5. After all, the process is reduced only to defining a few “bridged” classes that perform the tasks defined inside the corresponding bridge.

    Now, let’s move forward and see together how all the previous classes can be put to work conjunctly to demonstrate the real capacity offered by the bridge design pattern. Therefore, go ahead and read the final section of the article. I’ll be there, waiting for you.



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