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

Object Interaction and Mediator Classes in PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 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:
      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


    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


       · Over the course of this last tutorial of the series, the initial functionality of...
     

       

    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 4 hosted by Hostway
    Stay green...Green IT