Home arrow PHP arrow Page 4 - Handling File Data with the Facade Pattern in PHP 5

Putting all the classes to work together - PHP

Are you interested in learning the foundations of different structural patterns in PHP 5? If your answer is affirmative, then you should start reading this article immediately! Welcome to the last installment of the series “Introducing the Facade Pattern in PHP 5.” In two consecutive articles, this series shows you how to create and use facade classes in PHP-based development environments.

TABLE OF CONTENTS:
  1. Handling File Data with the Facade Pattern in PHP 5
  2. Using the facade pattern to handle file data
  3. Applying the facade pattern to a string processor
  4. Putting all the classes to work together
By: Alejandro Gervasio
Rating: starstarstarstarstar / 5
January 23, 2007

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

In this final section of the article, I’d like to show you how all the classes that I created previously can be put to work conjunctly. In this manner I'll demonstrate the neat functionality offered by the already familiar facade pattern.

Below I set up a short example. It shows the output generated by the pertinent file processing class, and the different results displayed by the respective facade class.

Having said that, here the complete source code that corresponds to the hands-on example in question:

// example using 'ProcessContentFacade' class
try{
   // instantiate new 'FileProcessor' object
   $fileProc=new FileProcessor();
   // write data to file
   $fileProc->writeData();
   // read and display file data before using 
   // 'ProcessContentFacade' class
   echo $fileProc->readData();
   /*
   displays the following:
   This string of data will be saved to file!
   */
   // reverse and uppercase file data by using
   // 'ProcessContentFacade' class
   $processedData=ProcessContentFacade::
processContent($fileProc->readData());
   echo $processedData;
   /* displays the following:
   !ELIF OT DEVAS EB LLIW ATAD FO GNIRTS SIHT
   */
}
catch(Exception $e){
   echo $e->getMessage();
   exit();
}

Without a doubt, after studying the above example, you’ll realize that implementing the facade pattern with PHP 5 is indeed a straightforward process that can be performed with only minor troubles. As usual, feel free to incorporate your own modifications to all the classes that were shown in this article. Doing so will help you acquire a more intimate grounding in how this design pattern works. Happy coding!

Final thoughts

Sadly, this is the end of this series. Over the course of these two tutorials, I introduced the fundamentals of how to apply the facade pattern in PHP 5. If you spend some time and practice with the examples that I provided you here, I’m pretty certain that you’ll end up having a reasonable experience on this pattern in particular.

See you in the next PHP tutorial!



 
 
>>> More PHP Articles          >>> More By Alejandro Gervasio
 

blog comments powered by Disqus
   

PHP ARTICLES

- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...
- PHP: Building Concrete Validators
- Sanitizing Input with PHP
- Executing Shell Commands with PHP
- Handling File Data with PHP
- File Security and Resources with PHP
- ArrayObject PHP Class Examples
- ArrayObject PHP Class: An Introduction
- Getting File System Data with PHP
- PHP Tools for Working with the File and Oper...
- Working with the File and Operating System w...
- PHP Proxy Patterns: Completing a Blog


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 1 - Follow our Sitemap

Dev Shed Tutorial Topics: