PHP
  Home arrow PHP arrow The Basics of Implementing Adapter Objects with PHP
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

The Basics of Implementing Adapter Objects with PHP
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 9
    2006-12-06


    Table of Contents:
  • The Basics of Implementing Adapter Objects with PHP
  • The basics of adapter objects
  • Defining a concrete directory processor class
  • Seeing the adapter 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


    The Basics of Implementing Adapter Objects with PHP
    ( Page 1 of 4 )

    You may have already encountered situations in coding PHP applications in which you would like to use inheritance, but could not for one reason or another. Fortunately, there is an alternative for these situations that can help you achieve the same result. In this first article in a two-part series, you'll learn about the adapter pattern.

    Introduction

    During your life as PHP developer, I’m quite sure you’ve been working with classes and objects for a while. That's very convenient for those times when you need to create a well-defined relationship between these classes, constructing web applications that are highly maintainable from the very beginning.

    In addition to mastering the main pillars of the object-oriented programming paradigm, like inheritance and polymorphism, probably you have already started implementing some kind of advanced interaction across several objects that goes beyond the boundaries of deriving a few subclasses from the corresponding parent class.

    Actually, while all this sounds good and seems to satisfy the most common requirements that must eventually be tackled when developing a certain PHP application, the truth is that sometimes using inheritance for creating specific objects inside a program isn’t convenient. This could be because all the pertinent base classes weren’t initially defined with a future expansion of their functionality in mind, or just because of simple ignorance.

    In either case, there must be an alternative way to extend the functionality of a base class without directly using inheritance. Also, at the same time, this approach has to be flexible enough to allow extending this parent class in such a way that a newly-created object can fit the particular requirements of another one. Does this sound a bit confusing? Fear not, because the topic is really understandable.

    To put things in a simpler way, say you have two predefined classes, where the first one must suit the demands of a second one, but as I said before, inheritance isn’t the most viable method for performing the corresponding coupling of classes. Now, after reading the above lines, you should be asking yourself: how can this be done?

    Fortunately for you and me, there’s a straightforward method for tackling the problem. It consists of creating what is called an “adapter” class. As you’ll see later on in this article, this adapting class will take the original one and modify --and eventually expand -- one or many of its methods to meet the specifications imposed by the destination class, all without appealing to the advantages of inheritance.

    In crude terms, this method is known popularly as the “adapter” pattern, and during this two-part series, I’ll be taking an in-depth look at it. In this way, you'll learn how to apply it within your own PHP applications and scripts.

    The subject is really interesting, thus let’s no waste more time in preliminaries and start learning more on how to create adapter objects with PHP. Let’s do it together!



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