Home arrow PHP arrow Completing a Sample String Processor with Method Chaining

Completing a Sample String Processor with Method Chaining

In this third part of a 12-part series on method chaining, I complete the definition of the sample string processor class. This process will help reaffirm the concepts that you learned before regarding the definition and implementation of chainable methods in PHP 5.

TABLE OF CONTENTS:
  1. Completing a Sample String Processor with Method Chaining
  2. Review: the string processor class
  3. Replacing characters of a string with HTML entities
  4. Replacing and reversing characters of a literal
By: Alejandro Gervasio
Rating: starstarstarstarstar / 1
October 28, 2009

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Method chaining is a simple, yet powerful, programming approach that permits you to write classes whose methods can be easily linked with each other, thus building a modular and highly-compact API. Logically, as with other methodologies, chainable methods are not a proprietary feature of a particular programming language, but rather an approach that can be used for developing both client and server-side web applications, and desktop programs as well.

Fortunately, PHP developers like you also can take advantage of the benefits of using method chaining when working with the object-oriented paradigm. In this series of articles you'll find numerous examples that not only will introduce you to the basics of this approach, but will show you how to use it in the context of real-world applications.

Naturally, if you already read the two preceding tutorials of the series, then at this stage you have a clearer idea of how to build chainable methods in PHP 5. In  those articles I developed a basic string processor class, which implemented some simple chainable methods for applying different filters to an incoming string.

In addition, it's fair to recall that this sample class defined a factory method (also chainable), which allowed you to create a singleton of the string processor without having to call its constructor directly.

However, it'd be pretty instructive to expand the existing functionality of the mentioned class by adding a few additional methods to it, which will also be  completely chainable. In this third chapter of the series I'm going to finish developing this string processor class by incorporating into it some chainable methods that will be tasked with replacing characters in an inputted string with their equivalent HTML entities, and with for reversing their value as well.

Now, it's time to continue creating more examples on using method chaining in PHP 5. Let's jump in!



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

blog comments powered by Disqus
   

PHP ARTICLES

- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...
- PHP: Building Concrete Validators
- Sanitizing Input with PHP
- Executing Shell Commands with PHP
- Handling File Data with PHP
- File Security and Resources with PHP
- ArrayObject PHP Class Examples
- ArrayObject PHP Class: An Introduction
- Getting File System Data with PHP
- PHP Tools for Working with the File and Oper...
- Working with the File and Operating System w...
- PHP Proxy Patterns: Completing a Blog


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 8 - Follow our Sitemap

Dev Shed Tutorial Topics: