PHP
  Home arrow PHP arrow Page 3 - More Examples of 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? 
PHP

More Examples of Creating Command Objects with PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 6
    2006-12-19


    Table of Contents:
  • More Examples of Creating Command Objects with PHP 5
  • Building an array command class
  • Creating two more command classes
  • Building an array commanded class
  • Including all the classes in one hands-on example

  • 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


    More Examples of Creating Command Objects with PHP 5 - Creating two more command classes
    ( Page 3 of 5 )

    As I stated in the previous section, I'd like to extend the initial example by creating two additional command classes. These classes will control programmatically by different methods the way that elements of a specified array are displayed. Keeping in mind this condition, in the following code sample I defined the "ArrayToLowerCommand" and "ArrayToReverse" classes respectively, which not surprisingly will turn into upper cased strings all the elements of an input array, in addition to reversing these elements as well.

    Please, take a look at the respective signatures for these new pair of classes:

    // define concrete 'ArrayToLowerCommand' class (implements concretely 
    the 'executeCommand()' method class ArrayToLowerCommand extends ArrayCommand{ public function executeCommand(){ $this->arrayCommanded->setLowercasedArray();           } } // define concrete 'ArrayToReverseCommand' class (implements concretely
    the 'executeCommand()' method class ArrayToReverseCommand extends ArrayCommand{ public function executeCommand(){ $this->arrayCommanded->setReversedArray();    } }

    In this case, the two new command classes listed above present signatures that are nearly identical to the previously defined "ArrayToUpperCommand" class. Of course, the only small difference rests on the definition of their respective "executeCommand()" methods, which perform distinct tasks, even when they're called the same.

    Also, it's important to stress a relevant point with reference to all the command classes: notice how they use an instance of the commanded object to perform well-differentiated processes, but in all the cases, the corresponding methods encapsulate the complete logic for doing their business only into the mentioned commanders. Are you starting to see how this pattern works now? I bet you are.

    Okay, at this stage you hopefully understand the principle that stands behind creating all these array command classes, but... what about defining the respective array commanded object?

    Fortunately for you and me, the creation of commanded objects is indeed a no-brainer process that can be done with minor hassles, something that I'm going to show you in the next few lines. Therefore, if you're curious about how these types of objects will be defined, please click on the link below and keep reading.



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

       

    PHP ARTICLES

    - 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
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





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