PHP
  Home arrow PHP arrow Page 2 - Creating AJAX Requester Objects with A...
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 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
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

Creating AJAX Requester Objects with Abstract Factory Classes in PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 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:
      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


    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


       · In this second article of the series, the abstract factory pattern is applied to...
     

       

    PHP ARTICLES

    - Authentication Scripts for a User Management...
    - Utilizing the Use Keyword for Namespaces in ...
    - Building a User Management Application
    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Database Security: Guarding Against SQL Inje...
    - Building a Modular Exception Class in PHP 5
    - Database and Password Security for Web Appli...
    - Handling MySQL Data Set Failures in PHP 5
    - Building Site Registration for Web Applicati...
    - Intercepting Customized Exceptions in PHP 5
    - Securing Your Web Application Against Attacks
    - Sub Classing Exceptions in PHP 5
    - Authentication for Web Application Security





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT