PHP
  Home arrow PHP arrow Page 4 - 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 - Demonstrating the functionality of the abstract factory pattern
    ( Page 4 of 4 )

    The best way to demonstrate the functionality offered by the abstract factory pattern is simply by setting up an instructive example where all the previously defined classes are used in conjunction.

    Bearing in mind the strong educational sense of the example in question, below I coded a short script. It illustrates how the two concrete factories that you learned in a previous section are capable of returning the correct type of AJAX objects to client code, depending on the context where they're used.

    Here is the sample script:

    try{
       // instantiate 'SynchronousAjaxRequesterFactory' object
       // (works in the 'synchronous' context)
       $factoryInstance=new SynchronousAjaxRequesterFactory();
       $syncRec1=$factoryInstance->createAjaxTextRequester();
       $syncReq1->send();
       $syncReq2=$factoryInstance->createAjaxXmlRequester();
       $syncReq2->send();
       // instantiate 'AsynchronousAjaxRequesterFactory' object
       // (works in the 'asynchronous' context)
       $factoryInstance=new AsynchronousAjaxRequesterFactory();
       $asyncReq1=$factoryInstance->createAjaxTextRequester();
       $asyncReq1->send();
       $asyncReq2=$factoryInstance->createAjaxXmlRequester();
       $asyncReq2->send();
    }
    catch(Exception $e){
       echo $e->getMessage();
       exit();
    }

    As illustrated above, after the first synchronous factory class has been instantiated, it makes sure that only synchronous AJAX objects are returned to client code, following the logic implemented by the abstract factory pattern. Similarly, once a new instance of the asynchronous factory class is created, naturally only asynchronous AJAX objects will be spawned. Simple and efficient!

    At this stage, I believe that the example shown above should give you an accurate idea of how the abstract factory pattern works. So go ahead with this recently-acquired background and start building your own abstract factory classes!

    Final thoughts

    Sadly, this is the end of this article. However, the overall experience has been educational, since you learned how to use the abstract factory pattern in PHP 5, in order to create AJAX objects that depend on a predefined context.

    But do you think this journey is over? Not at all, because in the last installment of this series, I'm going to show you how to use this useful pattern to build programmatically online forms. You won't want to miss it.



     
     
    >>> 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 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek