PHP
  Home arrow PHP arrow Page 3 - More Examples of Creating Command Obje...
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

More Examples of Creating Command Objects with PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 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:
      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


    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


       · Over the course of this second part of the series, you'll learn how to use command...
       · It's again clear what it does and how it does it, but it's not clear "why" I would...
       · Thank you for posting your comments here. Concerning your question, it doesn’t mean...
       · I trust that there are occasions where it could be usefull. I'd love to see a...
       · Thank you again for commenting here. I’ll keep in mind your suggestion on the...
       · A nice article and good explanation of how the command pattern works. I do agree...
       · Hi friend,Thank you for the kind comments about my article on the command...
       · I had the same exact question - why and when do you really have an advantage of...
       · Reading the first page of this article made me dizzy. I felt like I was reading one...
       · Hello Nikolai,Thank you for posting your questions here. As I said before, this...
       · Hello there,Thank you for commenting my PHP article, and certainly I accept your...
       · Thanks AlejandroA good working example of the described pattern and conveyed...
       · Hi Jon,Thank you for your positive comments on my PHP article. I really...
     

       

    PHP ARTICLES

    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Database Security: Guarding Against SQL Inje...
    - 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
    - Securing Your Web Application Against Attacks
    - Sub Classing Exceptions in PHP 5
    - Authentication for Web Application Security
    - Building a Content Management System with Co...
    - Filters and Login Systems for Web Applicatio...
    - Working with the Email Class in Code Igniter





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