PHP
  Home arrow PHP arrow Page 5 - 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 - Seeing the bridge pattern in action
    ( Page 5 of 5 )

    Logically, the best way to understand how the bridge pattern works rests on setting up an example where all the classes that were created previously are used together in the same script. In accordance with this, below I coded a few simple snippets which show how the bridge class saves a target object first to an array, then a text file, and finally a cookie. Thus, take a look at the list of try-catch blocks shown below:

    try{ // instantiate 'Message' object $msg=new Message('This a test string that will be saved later
    on'); // instantiate 'BridgeObjectSaver' object, and indicate that
    target object will be saved to array $bObjSaver=new BridgeObjectSaver($msg,'array'); // save target object to array $bObjSaver->save(); } catch(Exception $e){ echo $e->getMessage(); exit(); }           try{ // instantiate 'Message' object $msg=new Message('This a test string that will be saved later
    on'); // instantiate 'BridgeObjectSaver' object, and indicate that target object will be saved to file             $bObjSaver=new BridgeObjectSaver($msg,'file');             // save target object to text file             $bObjSaver->save(); } catch(Exception $e){ echo $e->getMessage(); exit(); } try{ // instantiate 'Message' object $msg=new Message('This a test string that will be saved later
    on'); // instantiate 'BridgeObjectSaver' object, and indicate that
    target object will be saved to a cookie $bObjSaver=new BridgeObjectSaver($msg,'cookie'); // save target object to a cookie $bObjSaver->save(); } catch(Exception $e){ echo $e->getMessage(); exit(); }

    As you’ll realize, the above examples demonstrate a clear implementation of the bridge pattern with PHP 5. Of course, if you’re interested in learning more on this pattern, feel free to modify the original source code that I showed here, and experiment with developing more complex examples.

    Conclusion

    In this first part of the series, I introduced the core concepts of the bridge design pattern in PHP 5. As you hopefully learned, this pattern allows you to separate a given class from its corresponding implementation, without using abstract classes.

    In the next part, I’m going to show you how to apply this pattern to create different data validation classes. The experience is really promising, therefore you don’t have any excuses to miss it!



     
     
    >>> 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