PHP
  Home arrow PHP arrow Method Chaining: Adding More Methods to the Chain
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

Method Chaining: Adding More Methods to the Chain
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 2
    2009-10-26


    Table of Contents:
  • Method Chaining: Adding More Methods to the Chain
  • Adding more methods to the string processor class
  • Adding another chainable method to the class
  • Defining a chainable factory method

  • 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


    Method Chaining: Adding More Methods to the Chain
    ( Page 1 of 4 )

    In this second part of a 12-part series on method chaining, I explain how to extend the functionality of the string processor class by adding to it a few simple chainable methods. I conclude this part by defining a factory method within the string processor class.

    Method chaining is a programming approach that permits you to chain multiple methods of a class in one single step, to perform several tasks in the context of a specified application.

    Logically, this approach can be used equally with various programming languages, and PHP 5 certainly is no exception. Therefore, if you’re a PHP developer who wants to learn the basic concepts that surround the definition and implementation of chainable methods using PHP 5, then in this group of articles you’ll find the material that you’ve been looking for.

    And now that you've been introduced to the primary goal of this article series, it’s time to review the topics that were covered in the last tutorial. In that article I proceeded to build a simple string processor class. It implemented a bunch of basic methods for performing some common tasks on an inputted string, such as removing unwanted tags from it, and upper casing and lower casing its characters.

    Naturally, the most important thing to point out here is that despite the simplicity of the methods, they could be chained to each other, thus allowing us to use the class’ API in a much more compact and tight way.

    Nonetheless, the functionality of this sample class can be enhanced through the codification of other chainable methods. What’s more, it’s possible to define a static factory method, also chainable, that allows you to create instances of the class without directly calling its constructor.

    Bearing in mind all of these interesting possibilities, in this second part of the series I’m going to demonstrate how to accomplish these tasks in a truly friendly fashion, as usual by coding some comprehensive hands-on examples.

    Now, let’s leave the preliminaries behind us and continue exploring the advantages of using method chaining in PHP 5. Let’s get going!



     
     
    >>> More PHP Articles          >>> More By Alejandro Gervasio
     

       

    PHP ARTICLES

    - 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
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek