PHP
  Home arrow PHP arrow Page 3 - 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 bridge pattern’s core logic
    ( Page 3 of 5 )

    In consonance with the intrinsic definition of the bridge pattern, it should be possible to separate a given class from its concrete implementation (without using abstract classes at all), since both of them will reside on different class hierarchies. This concept will be much easier to grasp if you take a look at the signature of the following bridge class, which takes up objects of type “Message” and saves them to different locations.

    That being said, the definition for this brand new class is as follows:

    // define class 'BridgeObjectSaver' class BridgeObjectSaver{ private $messageObj; private $objSaver; public function __construct(Message $messageObj,$saveCommand){ if(!in_array($saveCommand,array('array',
    'file','cookie'))){ throw new Exception('Invalid save command'); } $this->messageObj=$messageObj; // target object is saved to array if($saveCommand=='array'){ $this->objSaver=newObjectToArraySaver(); } // target object is saved to file elseif($saveCommand=='file'){ $this->objSaver=new ObjectToFileSaver(); } // target object is saved to a cookie else{ $this->objSaver=new ObjectToCookieSaver(); } } public function save(){ $this->objSaver->save($this->messageObj); } }

    As shown above, this completely new “BridgeObjectSaver” class is capable of storing an object of type “Message” in different places, such as a plain text file, an array or a simple cookie. Nevertheless, I’d like you to study specifically how all these tasks are performed by the mentioned bridge class.

    As you can see, there’s a third object involved in this process called “ObjectSaver.” This object actually carries out all the storage procedures that I discussed before. Obviously the “BridgeObjectSaver” class behaves like a real “bridge” for “ObjectSaver” (hence the name of the pattern). At the same time, it fits the requirements of the bridge pattern, since its respective definition and implementation reside on different class hierarchies. Isn’t this great? Of course it is!

    After examining the definition for the previous bridge class, surely you’ll think that creating these kinds of structures with PHP 5 is actually a straightforward process, therefore let’s move on and learn together how to build the corresponding object saver classes that were defined before.

    To see how these classes will be properly created, please click on the link below and keep reading.



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