PHP
  Home arrow PHP arrow Page 4 - 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 - Building an array commanded class


    (Page 4 of 5 )

    To complete the adequate implementation of the command pattern, I need to define another class. This one will be called "ArrayCommanded." According to the definition of the pattern in question, it will be responsible for encapsulating into different methods all the logic required for manipulating the format of the elements that correspond to an inputted array.

    Does this sound a bit confusing? Fear not, because it isn't. Please, take a look at the signature for this new class to clarify your possible questions:

    // define 'ArrayCommanded' class 
    class ArrayCommanded{
    private $inputArray;
    public function __construct($inputArray){
    $this->setInputArray($inputArray);
    }
    public function setInputArray($inputArray){
    if(!is_array($inputArray)||count($inputArray)<1){
    throw new Exception('Input data must be a 
    non-empty array!');                         }                         $this->inputArray=$inputArray; } public function getinputArray(){ return $this->inputArray; } // uppercase input array (encapsulates all the logic to execute
    the method in the command object) public function setUppercasedArray(){ $this->setinputArray(array_map('strtoupper',$this->
    getInputArray())); } // lowercase input array (encapsulates all the logic to execute
    the method in the command object) public function setLowercasedArray(){ $this->setinputArray(array_map('strtolower',
    $this->getInputArray())); } // reverse input array (encapsulates all the logic to execute
    the method in the command object) public function setReversedArray(){ $this->setinputArray(array_reverse($this->
    getInputArray())); } }

    As I said previously, the above "ArrayCommanded" class presents all the required methods. This is useful for processing the format that corresponds to the elements of the "$inputArray" array. Even when the logic implemented by the referenced methods is very easy to follow, it demonstrates in a clear fashion how a single commanded class can be constructed in such a way that it can accept instructions from different commanders. Isn't this great?

    All right, now that you've learned how the commanders were appropriately created, in conjunction with defining their corresponding commanded class, it's time to move forward and tackle the last section of this article. I will show you how all these classes can work together; in short, you'll see the commander pattern in action.

    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