PHP
  Home arrow PHP arrow Page 3 - Using the Memento Pattern with a File ...
Dev Shed Forums 
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

Using the Memento Pattern with a File Reading Class
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 3
    2007-01-15

    Table of Contents:
  • Using the Memento Pattern with a File Reading Class
  • Building an originator class
  • Defining the signature of a caretaker class
  • The memento design pattern in action

  • 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


    Using the Memento Pattern with a File Reading Class - Defining the signature of a caretaker class


    (Page 3 of 4 )

    As you might have guessed, the functionality of a caretaker class has to be strongly related to the nature of the tasks performed by the originator. Keeping in mind this basic principle, below I listed the definition for the corresponding caretaker. In a fit of inspiration, I named it "FileDataSeeker." Take a look at it, please:

    // define 'FileDataSeeker' class (in this case, this is the
    Caretaker class)
    class FileDataSeeker{
       private $filePointer;
       // the constructor takes up the originator object as the only
    input parameter
       public function __construct(FileDataReader $fileDataReader){
         $this->setFilePointer($fileDataReader);
       }
       public function setFilePointer(FileDataReader $fileDataReader){
         $this->filePointer=$fileDataReader->getFilePointer();
       }
       public function getFilePointer(FileDataReader $fileDataReader){
         $fileDataReader->setFilePointer($this->filePointer);
       }
    }

    As illustrated above, the "FileDataSeeker" class has some useful methods for handling the "filePointer" property that belongs to the respective originator class. These methods will help this caretaker class to carry out its responsibility to store the value of the property. Thus, the value can be retrieved at a later time. Pretty logical, isn't it?

    By providing the "FileDataSeeker" class with this ability, if the file reading class locates its file pointer at a non-existent place, it will be possible to move it back to a valid position via the respective caretaker. Definitely, that makes a lot of sense!

    However, showing you the originator and the caretaker separately won't give you a clear idea of how they work. Thus, in response to this issue, in the next section I'll create a simple script, which hopefully will demonstrate the power of these two classes when they operate together.

    As usual, to see how this will be achieved, go ahead and read the following section. I'll be there, waiting for you.

    More PHP Articles
    More By Alejandro Gervasio


       · Over this final article of the series, you'll learn how to use the memento pattern...
     

       

    PHP ARTICLES

    - Using Aliases and the Autoload Function with...
    - Authentication Scripts for a User Management...
    - Utilizing the Use Keyword for Namespaces in ...
    - Building a User Management Application
    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - 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
    - Sub Classing Exceptions in PHP 5
    - Building a Content Management System with Co...
    - Filters and Login Systems for Web Applicatio...

     
    Application Delivery: Everything You Wanted to Know, but Didn`t Know You Needed to Ask
    A comprehensive guide to examining the topics of Wide-area Data Services and app....

     
    Best Practices: Safe and Secure Hardware Asset Recovery
    Companies increasingly must meet EPA and local requirements for the disposal of ....

     
    Managing SSL Security in Multi-Server Environments
    Read this white paper to learn how to simplify management of your organization's....

     
    Open Source Security Myths
    Open Source Software (OSS) is computer software whose source code is available t....

     
    Power and Cooling Capacity Management for Data Centers
    This paper describes the principles for achieving power and cooling capacity man....

     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
    Stay green...Green IT