PHP
  Home arrow PHP arrow Page 2 - 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 - Introducing the basics of the bridge pattern
    ( Page 2 of 5 )

    Naturally, a good place to start demonstrating the creation and usage of bridge objects with PHP 5 is with developing a practical example where these types of objects are utilized to perform a given task.

    In this case, the example that I’m going to set up will be based upon creating first a target object, called “Message,” which will be tasked with displaying some trivial strings to the browser. Next, I’m going to define a bridge class that will be capable of saving the mentioned target object to different storage locations, like a plain text file, an array structure and a simple cookie.

    Hopefully, after you see how this bridge class looks, you’ll realize how its instantiation can be separated from its corresponding implementation, since both things will reside on different class hierarchies.

    So far, so good. The process for building a bridge class seems really straightforward, therefore let me show you the first target class involved in this creation process. As I said before , it is named “Message,” and its simple signature is shown below:

    // define 'Message' class (target object for 'BridgeObjectSaver' class) class Message{ private $message; public function __construct($message='Default Message'){ if(!$message||!is_string($message)||strlen
    ($message)>255){ throw new Exception('Invalid input message'); } $this->message=$message; } public function getMessage(){ return $this->message; } }

    As illustrated above, the “Message” sample class is really simple to understand. All this class does is accept an input string as the unique parameter, which will be returned to calling code with the trivial purpose of being displayed on the browser, or receiving similar processing. Extremely easy, right?

    Well, I have to admit that the previous target class is rather primitive, but for my purpose of showing you how a bridge class can be created with PHP 5, the definition for this class is more than enough, at least for now.

    Therefore, having shown the signature of the respective “Message” class, it’s a good time to leap forward and learn how to build a bridge class. This class will use “Message” objects and save them to different storage locations, including text files, arrays and cookies respectively.

    Do you want to see how this brand new bridge class will be created? All right, jump into the following section 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 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek