PHP
  Home arrow PHP arrow Page 3 - Introduction to Creating Command Objec...
Dev Shed Forums 
Administration  
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 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Actuate Whitepapers 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
IBM Rational Software Development Conference
 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

Introduction to Creating Command Objects with PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 13
    2006-12-12

    Table of Contents:
  • Introduction to Creating Command Objects with PHP 5
  • Creating a command class
  • Creating additional command classes
  • Defining a commanded class
  • 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

    Learn four approaches for automating Excel logic, along with advantages and disadvantages of each. Read all about it in the free whitepaper: “Tapping into Excel Logic from Java: Four Server-Based AlternativesDownload Now!

    Introduction to Creating Command Objects with PHP 5 - Creating additional command classes
    (Page 3 of 5 )

    As you learned in the previous section, the command class, called "StringToUpperCommand," was responsible for executing the corresponding "setUppercasedString()" method, in this case provided by the commanded object. This fact demonstrates, in a clear way, the structure of the command pattern, since the method I mentioned previously houses all the logic required to be called into the pertinent command class.

    However, as you saw previously, the command class that I just defined is capable of instructing the commanded object to uppercase a specified input string. Therefore, and considering the intrinsic versatility of the command pattern, I'm going to create a few additional command classes, so that you can understand how one single commanded object can receive "orders" from different commanders. That would definitely be interesting, right?

    Okay, that being said, below I coded a couple of extra command classes. These classes are tasked with upper-casing and reversing a given string in the commanded object via their corresponding "executeCommand()" methods. The signatures for these brand new classes are as follows:

    // define concrete 'StringToLowerCommand' class (implements concretely
    the 'executeCommand()'method class StringToLowerCommand extends DataCommand{        public function executeCommand(){                $this->dataCommanded->setLowercasedString();                   } } // define concrete 'StringToReverseCommand' class (implements concretely
    the 'executeCommand()'method class StringToReverseCommand extends DataCommand{       public function executeCommand(){                $this->dataCommanded->setReversedString();          } }

    As you'll possibly realize, the two command classes defined above are very similar to the first one that I coded in the previous section. Naturally, the only difference to spot here is the implementation of each of their "executeCommand()" methods, which are responsible for upper-casing and reversing a given input string into the corresponding $dataCommanded object.

    At this point, and after defining the three previous command classes, it's time to move forward and learn how to create the long awaited commanded class, since I haven't shown how it will look.

    In the next few lines I'll demonstrate how to define this relevant class, therefore if you're interested in learning how this process will be achieved, click on the link that appears below and keep reading.

    More PHP Articles
    More By Alejandro Gervasio


       · In this first article of the series, you'll learn the key points of applying the...
       · This is a good example of the Command pattern in PHP, i'm not sure why you've moved...
       · Hi James,Thank you for commenting on my PHP article. With reference to your...
     

       

    PHP ARTICLES

    - Protecting PHP 5 Class Data with Member Visi...
    - Setting Up a Web-based Image Hosting Service
    - Comparing Files and Databases with PHP Bench...
    - Setting Up a Web-Based Image Gallery
    - Using Timers to Benchmark PHP Applications
    - Benchmarking Applications with PHP
    - Setting Up a Web-Based File Manager: PHPfile...
    - Developing a Modular Class For a PHP File Up...
    - Setting Up a Web-Based File Manager: bfExplo...
    - Defining a Custom Function for File Uploader...
    - Parsing Child Nodes with the DOM XML extensi...
    - Creating an Error Handling Module for a PHP ...
    - Accessing Attributes and Cloning Nodes with ...
    - Retrieving Information on Selected Files wit...
    - Handling HTML Strings and Files with the DOM...

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway