PHP
  Home arrow PHP arrow Page 3 - Introduction to Creating Command Objects with 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

Introduction to Creating Command Objects with PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 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:
      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


    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
     

       

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