PHP
  Home arrow PHP arrow The Basics of Implementing Adapter Obj...
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Actuate Whitepapers 
Moblin 
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? 
PHP

The Basics of Implementing Adapter Objects with PHP
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 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:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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

    Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!

    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


       · Over the course of this first tutorial, you'll learn the foundations on how to...
     

       

    PHP ARTICLES

    - Handling Attachments in MIME Email with PHP
    - Completing the Project Management Application
    - Sending MIME Email with PHP
    - Handling Files for a Project Management Appl...
    - Viewing and Editing Tasks for a Project Mana...
    - More on Private Methods with PHP 5 Member Vi...
    - Adding Tasks to a Project Management Applica...
    - Utilizing Private Methods with PHP 5 and Mem...
    - Making Changes in a Project Management Appli...
    - Defining Public and Protected Methods with M...
    - HTML for a Project Management Application
    - Using Subclasses and Accessors with Member V...
    - Implementing Internet Protocols with PHP
    - Project Management: The Application
    - Working with Private Properties to Protect P...




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway