PHP
  Home arrow PHP arrow Page 2 - Creating AJAX Requester Objects with Abstract Factory Classes in 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

Creating AJAX Requester Objects with Abstract Factory Classes in PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 5
    2007-01-31


    Table of Contents:
  • Creating AJAX Requester Objects with Abstract Factory Classes in PHP 5
  • Working with AJAX HTTP requester objects
  • Completing the schema imposed by the abstract factory pattern
  • Demonstrating the functionality of the abstract factory pattern

  • 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


    Creating AJAX Requester Objects with Abstract Factory Classes in PHP 5 - Working with AJAX HTTP requester objects
    ( Page 2 of 4 )

    To illustrate in a friendly fashion how the abstract factory pattern can be used to spawn different HTTP requester objects, I'm going to define an abstract factory class which will determine what type of AJAX objects will be created by the corresponding concrete factories.

    In this case, I decided to provide this abstract factory with the capability to work with text and XML-based HTTP requester objects. Its definition is as follows:

    // define abstract 'AbstractAjaxRequesterFactory' class
    abstract class AbstractAjaxRequesterFactory{
       abstract public function createAjaxTextRequester();
       abstract public function createAjaxXmlRequester();
    }

    As you can see, even when the signature for the abstract factory class is brief, it shows clearly the nature of the objects that should be created by two non-abstract factories. In this case, these two concrete factories are responsible for returning to calling code at least two types of requester objects, called "AJAXTextRequester" and "AJAXXmlRequester" respectively.

    As you might have guessed, the first requester object will be capable of returning to the client all the server responses as plain text via the corresponding "responseText" property offered by AJAX. The second one will return all the server outputs in XML format, logically, by using the "responseXML" property.

    As you'll probably realize, the two types of HTTP requester objects that must be created by the corresponding concrete factories are pretty straightforward. Therefore let me move on and show you the respective signatures for these factories, which will be created as subclasses of the abstract one.

    Having said that, take a look at the following child classes, which are responsible for spawning the two kinds of HTTP requester objects mentioned before. Here they are:

     // define concrete 'SynchronousAjaxRequesterFactory' class
    class SynchronousAjaxRequesterFactory extends AbstractAjaxRequesterFactory{
       private $context='synchronous';
       public function createAjaxTextRequester(){
         return new SynchronousAjaxTextRequester();
       }
       public function createAjaxXmlRequester(){
         return new SynchronousAjaxXmlRequester();
       }
    }
    // define concrete 'AsynchronousAjaxRequesterFactory' class
    class AsynchronousAjaxRequesterFactory extends
    AbstractAjaxRequesterFactory{
       private $context='asynchronous';
       public function createAjaxTextRequester(){
         return new AsynchronousAjaxTextRequester();
       }
       public function createAjaxXmlRequester(){
         return new AsynchronousAjaxXmlRequester();
       }
    }

    After defining the couple of concrete factory classes listed above, I'm pretty certain that you see more clearly the kind of HTTP requester objects created by each one of them.

    With reference to the first factory class, you can see that it works on the "synchronous" context and logically must spawn only synchronous AJAX objects. Meanwhile, the signature of the second factory class demonstrates that only asynchronous objects will be returned to client code. That was pretty simple to grasp, wasn't it?

    Besides, you should notice that whether a factory class is used in a "synchronous" or "asynchronous" context, in both cases it's capable of creating text-based or XML-based requester objects.

    Well, having explained how each concrete factory class works in its corresponding context, I think it's a good time to move forward and proceed to show the respective definitions for all the classes that are tasked with spawning AJAX objects.

    Of course, the signatures that correspond to all these brand new classes will be covered in the next few lines, thus I recommend that you click on the link that appears 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