PHP
  Home arrow PHP arrow Page 2 - Object Interaction and Mediator Classes in 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

Object Interaction and Mediator Classes in PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 5
    2007-03-20


    Table of Contents:
  • Object Interaction and Mediator Classes in PHP 5
  • Expanding the initial mediator class
  • Building some additional file handling classes
  • Implementing the mediator pattern

  • 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


    Object Interaction and Mediator Classes in PHP 5 - Expanding the initial mediator class
    ( Page 2 of 4 )

    As you'll surely recall, in the preceding article of this series I defined a mediator class, which was called "FileHandlerMediator." The purpose of creating this class was to demonstrate the capacity of a mediator structure for synchronizing two different objects.

    In this specific case, the objects were conceived as simple file handlers for manipulating numeric and alphabetic data respectively. Nevertheless, I stated in the previous section that my objective was to expand the initial functionality of this file handler mediator class so it could maintain three (not only two) objects in perfect synchronization.

    Even though this sounds like a hard thing to accomplish, it's much simpler than you may think. Let me show you the improved signature of this mediator class, this time including the required modifications that allow it to synchronize three different file handlers.

    That being said, the definition for this class is as follows:     

    // define 'FileHandlerMediator' class
    class FileHandlerMediator{
       private $numericFileHandler;
       private $alphabeticFileHandler;
       private $alphanumericFileHandler;
       public function __construct
    ($numericData,$alphabeticData,$alphanumericData){
         $this->numericFileHandler=new NumericFileHandler
    ($numericData,$this);
         $this->alphabeticFileHandler=new AlphabeticFileHandler
    ($alphabeticData,$this);
         $this->alphanumericFileHandler=new AlphanumericFileHandler
    ($alphanumericData,$this);
       }
       public function getNumericFileHandler(){
         return $this->numericFileHandler;
       }
       public function getAlphabeticFileHandler(){
         return $this->alphabeticFileHandler;
       }
       public function getAlphanumericFileHandler(){
         return $this->alphanumericFileHandler;
       }
       // this method lowercase and uppercase respectively the data of the other file handlers
       public function modifyFileData(FileHandler $fileHandler){
         if($fileHandler instanceof NumericFileHandler){
           if($fileHandler->getStatus()=='uppercased'){
             if($this->getAlphabeticFileHandler()->getStatus()!
    ='uppercased'){
               $this->getAlphabeticFileHandler()-
    >uppercaseFileData();
             }
             if($this->getAlphanumericFileHandler()->getStatus
    ()!='uppercased'){
               $this->getAlphanumericFileHandler()-
    >uppercaseFileData();
             }
           }
           elseif($fileHandler->getStatus()=='lowercased'){
             if($this->getAlphabeticFileHandler()->getStatus()!
    ='lowercased'){
               $this->getAlphabeticFileHandler()-
    >lowercaseFileData();
             }
             if($this->getAlphanumericFileHandler()->getStatus
    ()!='lowercased'){
               $this->getAlphanumericFileHandler()-
    >lowercaseFileData();
             }
           }
         }
         elseif($fileHandler instanceof AlphabeticFileHandler){
           if($fileHandler->getStatus()=='uppercased'){
             if($this->getNumericFileHandler()->getStatus()!
    ='uppercased'){
               $this->getNumericFileHandler()-
    >uppercaseFileData();
             }
             if($this->getAlphanumericFileHandler()->getStatus
    ()!='uppercased'){
               $this->getAlphanumericFileHandler()-
    >uppercaseFileData();
             }
           }
           elseif($fileHandler->getStatus()=='lowercased'){
             if($this->getNumericFileHandler()->getStatus()!
    ='lowercased'){
               $this->getNumericFileHandler()-
    >lowercaseFileData();
             }
             if($this->getAlphanumericFileHandler()->getStatus
    ()!='lowercased'){
               $this->getAlphanumericFileHandler()-
    >lowercaseFileData();
             }
           }           
         }
         elseif($fileHandler instanceof AlphanumericFileHandler){
           if($fileHandler->getStatus()=='uppercased'){
             if($this->getAlphabeticFileHandler()->getStatus()!
    ='uppercased'){
               $this->getAlphabeticFileHandler()-
    >uppercaseFileData();
             }
             if($this->getNumericFileHandler()->getStatus()!
    ='uppercased'){
               $this->getNumericFileHandler()-
    >uppercaseFileData();
             }
           }
           elseif($fileHandler->getStatus()=='lowercased'){
             if($this->getAlphabeticFileHandler()->getStatus()!
    ='lowercased'){
               $this->getAlphabeticFileHandler()-
    >lowercaseFileData();
             }
             if($this->getNumericFileHandler()->getStatus()!
    ='lowercased'){
               $this->getNumericFileHandler()-
    >lowercaseFileData();
             }
           }           
         }                       
       }
    }

    I modified the structure of the previous mediator class to provide it with the capacity for synchronizing three different file handlers. In this case, these file handlers deal with numeric and alphabetic data, and alphanumeric values as well.

    It's worth stressing here that each time a file handler object changes the case of the data that it manipulates, this variation is also introduced by the other handlers via the respective mediator. The "modifyFileData()" method, which has been coded above, demonstrates how this synchronization between objects is performed by a few simple PHP sentences.

    At this stage, I illustrated in a friendly way how the structure of the mediator class that you learned before can be modified with the purpose of synchronizing three distinct file handlers. However, the signatures of these objects still remain undefined. In the upcoming section I'm going to show you their definitions. Please click on the link 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 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek