PHP
  Home arrow PHP arrow Page 2 - Working with Strings and the Composite...
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

Working with Strings and the Composite Pattern in PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 3
    2007-03-14

    Table of Contents:
  • Working with Strings and the Composite Pattern in PHP 5
  • Handling strings of data
  • Defining the SingleStringProcessor and MultipleStringProcessor classes
  • Putting all the classes to work together

  • 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


    Working with Strings and the Composite Pattern in PHP 5 - Handling strings of data


    (Page 2 of 4 )

    In consonance with the objective of this tutorial, I’m going to build an abstract class. The class will define a generic model for creating some simple string processor objects.

    Later on, based on the structure provided by this base class, I’m going to derive from it a pair of subclasses. Despite their different implementations, these subclasses will expose the same behavior when used within the context of a given PHP application.

    As you may have noticed, this is exactly the intrinsic definition of the composite pattern. Having said that, please pay attention to the definition of the abstract class, shown below:    

    // define abstract 'StringProcessor' class
    abstract class StringProcessor{
       // get information about selected string
       abstract public function getSelectedStringInfo(
    $singleStringProcessor);
       // get number of string processors
       abstract public function getNumberOfStringProcessors();
       // add new string processor
       abstract public function addStringProcessor(
    $singleStringProcessor);
    }

    As you can see, the above “StringProcessor” class presents a few generic methods that obviously will come in handy for performing some useful tasks. These tasks include getting information about a specific string of data, and counting and adding new string processor objects, which are inputted straight into the class via some of these methods.

    However, don’t worry for the moment about how all these string processors will be defined, since I’ll be demonstrating how they look in the section to come.

    All right, at this stage I simply created the abstract class that you saw before, but maybe you’re wondering…how does this fit into the schema imposed by the composite pattern?

    Good question! Fortunately, the answer is quite simple. Since the composite pattern states clearly that one object or a group of objects will expose the same behavior across a given application, in the next few lines I’m going to create two subclasses from the base “StringProcessor.”

    As you’ll see, these child classes will behave identically, in this way implementing the programmatic model dictated by the aforementioned pattern. Quite simple, isn’t it?

    Okay, at this moment I’m pretty sure that you want to learn how these subclasses will be created, so click on the link that appears below and keep reading.

    More PHP Articles
    More By Alejandro Gervasio


       · In this second (and final) article of the series, the composite pattern is...
     

       

    PHP ARTICLES

    - Using Aliases and the Autoload Function with...
    - 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
    - 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
    - Sub Classing Exceptions in PHP 5
    - Building a Content Management System with Co...
    - Filters and Login Systems for Web Applicatio...

     
    Application Delivery: Everything You Wanted to Know, but Didn`t Know You Needed to Ask
    A comprehensive guide to examining the topics of Wide-area Data Services and app....

     
    Best Practices: Safe and Secure Hardware Asset Recovery
    Companies increasingly must meet EPA and local requirements for the disposal of ....

     
    Managing SSL Security in Multi-Server Environments
    Read this white paper to learn how to simplify management of your organization's....

     
    Open Source Security Myths
    Open Source Software (OSS) is computer software whose source code is available t....

     
    Power and Cooling Capacity Management for Data Centers
    This paper describes the principles for achieving power and cooling capacity man....

     




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