PHP
  Home arrow PHP arrow Page 4 - 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 - Implementing the mediator pattern


    (Page 4 of 4 )

    As I stated in the section that you just read, here is the pertinent example. It shows how the mediator that was defined previously is used by the respective file handlers to change the case of the data that correspond to each of the objects.

    Having said that, the code sample is as follows:

    try{
       // get different type of file data
       $numData=file_get_contents('data1.txt');
       $alphaData=file_get_contents('data2.txt');
       $alphanumData=file_get_contents('data3.txt');
       // instantiate 'FileHandler' class
       $fileHandlerMediator=new FileHandlerMediator
    ($numData,$alphaData,$alphanumData);
       // instantiate file handler classes
       $numericFileHandler=
    $fileHandlerMediator->getNumericFileHandler();
       $alphabeticFileHandler=
    $fileHandlerMediator->getAlphabeticFileHandler();
       $alphanumericFileHandler=
    $fileHandlerMediator->getAlphanumericFileHandler();
       // display data of different file handlers
       echo $numericFileHandler->getFileData().'<br />';
       echo $alphabeticFileHandler->getFileData().'<br />';
       echo $alphanumericFileHandler->getFileData().'<br />';
               

       /* displays the following
       12345
       This is alphabetic data
       This is line 1 of alphanumeric data
       */

       // uppercase numeric file data (also changes the case of other file data)
       $numericFileHandler->uppercaseFileData();
       echo $numericFileHandler->getFileData().'<br />';
       echo $alphabeticFileHandler->getFileData().'<br />';
       echo $alphanumericFileHandler->getFileData().'<br />';

       /* displays the following
       12345
       THIS IS ALPHABETIC DATA
       THIS IS LINE 1 OF ALPHANUMERIC DATA
       */

       // lowercase numeric file data (also changes the case of other file data)
       $numericFileHandler->lowercaseFileData();
       echo $numericFileHandler->getFileData().'<br />';
       echo $alphabeticFileHandler->getFileData().'<br />';
       echo $alphanumericFileHandler->getFileData().'<br />';

       /* displays the following
        12345
        this is alphabetic data
        this is line 1 of alphanumeric data
       */           

       // uppercase alphabetic file data (also changes the case of other file data)
       $alphabeticFileHandler->uppercaseFileData();
       echo $numericFileHandler->getFileData().'<br />';
       echo $alphabeticFileHandler->getFileData().'<br />';
       echo $alphanumericFileHandler->getFileData().'<br />';

       /* displays the following
       12345
       THIS IS ALPHABETIC DATA
       THIS IS LINE 1 OF ALPHANUMERIC DATA
       */

       // lowercase alphanumeric file data (also changes the case of other file data)
       $alphanumericFileHandler->lowercaseFileData();
       echo $numericFileHandler->getFileData().'<br />';
       echo $alphabeticFileHandler->getFileData().'<br />';
       echo $alphanumericFileHandler->getFileData().'<br />';

       /* displays the following
       12345
       this is alphabetic data
       this is line 1 of alphanumeric data
       */
    }
    catch(Exception $e){
       echo $e->getMessage();
       exit();
    }

    Pretty good, isn't it? As you can see, the previous example demonstrates in a clear way how each change introduced by a particular file handler is reflected and updated by the others, in this manner achieving perfect synchronization across all the involved objects.

    Logically, this updating process is performed via the respective mediator, thus I believe that the above example should be more than enough to illustrate the functionality provided by this helpful pattern.

    Final thoughts

    Sad but true, we've come to the end of this series. Hopefully, after reading the two tutorials that comprise it, you'll have a more solid grounding in how the mediator pattern works, and how it can be implemented quickly with PHP 5.

    See you in the next PHP tutorial!


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

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