PHP
  Home arrow PHP arrow Page 2 - 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 
Moblin 
JMSL Numerical Library 
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


    The Basics of Implementing Adapter Objects with PHP - The basics of adapter objects


    (Page 2 of 4 )

    As you read in the introduction of this article, adapter objects can be useful for modifying the original structure of a specified class, but in this case without having to use inheritance to perform the corresponding structural changes.

    Once the initial class have been altered via the mentioned adapter, an instance of it is usually passed in to another class, which expects the inputted object to conform the characteristics of a predefined model.

    Of course, all this theory sounds interesting, but I’m sure that you want to see how the respective concepts can be translated into some pieces of functional PHP code. Therefore, my next step will be to set up a concrete example, where you can understand with minor hassles how an adapter class can be properly created.

    First I’ll start developing the referenced example by coding the basic structure of a directory processor class with PHP 5. Then I'll create a simple adapter class to illustrate the complete procedure, aimed at “adapting” the signature of the mentioned directory processor.

    Having said that, here is the definition for the new “AbstractDirectoryProcessor” class. As its name indicates, it defines the generic model of a directory handling object. Please look at the following class:

    //define abstract 'AbstractDirectoryProcessor' class abstractclass AbstractDirectoryProcessor{ private $dirPath; abstract public function fetchDirContent(); abstract public function getDirInfo(); }

    As illustrated in the above example, the initial definition that corresponds to the “AbstractDirectoryProcessor” class outlines the generic interface that will be implemented by all the eventual child classes derived from it.

    In this particular case, two abstract methods called “fetchDirContent()” and “getDirInfo()” respectively have been appropriately declared, which suggest clearly what type of tasks will be performed by the eventual subclasses, once the respective methods have been concretely implemented.

    As you might have guessed, the first method will be used for retrieving the contents of a given directory, while the second one will be tasked with displaying some useful information about the directory in question. This is quite simple, isn’t it?

    Now that you learned how the previous “AbstractDirectoryProcessor” class was defined, it’s time to see how a concrete directory handling class can be created, based upon the structure of the corresponding parent class that you saw before.

    That’s exactly the topic that will be treated in the following section, therefore click on the link that appears below and keep reading.

    More PHP Articles
    More By Alejandro Gervasio


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

       

    PHP ARTICLES

    - Validating Web Forms with the Code Igniter P...
    - Output Buffering
    - Paginating Database Records with the Code Ig...
    - HTTP Headers in Web Development
    - Project Management: Administration
    - Building a Database-Driven Application with ...
    - User Authentication for a Project Management...
    - Introduction to the CodeIgniter PHP Framework
    - Adding Users for a Project Management Applic...
    - Migrating Class Code for a MIME Email to PHP...
    - Login and Logout Authentication for a Projec...
    - Composing Messages in HTML for MIME Email wi...
    - Project Management: Authentication
    - A Better Way to Determine MIME Types for MIM...
    - Project Management Overview





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