PHP
  Home arrow PHP arrow Page 3 - Using the Memento Pattern with a File Reading Class
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? 
PHP

Using the Memento Pattern with a File Reading Class
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 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:
      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


    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
     

       

    PHP ARTICLES

    - 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
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    Stay green...Green IT