Home arrow PHP arrow Using the Memento Pattern with a File Reading Class

Using the Memento Pattern with a File Reading Class

The memento pattern can be used to maintain the state of a property that belongs to a specific class. If you want to learn more about how to do this, start reading this tutorial! Welcome to the final installment of the series "Maintaining the State of Classes." In two parts, this series teaches you how to use the memento design pattern with PHP 5, and it accompanies the corresponding theoretical concepts with diverse hands-on examples.

TABLE OF CONTENTS:
  1. Using the Memento Pattern with a File Reading Class
  2. Building an originator class
  3. Defining the signature of a caretaker class
  4. The memento design pattern in action
By: Alejandro Gervasio
Rating: starstarstarstarstar / 3
January 15, 2007

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Introduction

If you already read the first article of the series, then you'll surely recall what this pattern is about. Just in case the subject doesn't ring any bells to you, however, let me offer you a quick introduction. In short, when the memento pattern is applied, two classes are required to satisfy a well-defined model: the "originator" and the "caretaker." 

Where this pattern is used, the caretaker is capable of holding the value of one or more properties that belong to the respective originator. Nevertheless, a classic implementation of these two classes means usually that the referenced caretaker can't directly access the properties of the originator. So how can its state be maintained? Usually the caretaker takes the originator as an input parameter, and uses all its methods to gain access to the respective properties.

All right, I think that the previous explanation should give you an accurate idea of how this pattern works. Let me now introduce the topics that I'll be covering in this last article of the series. I'll show you how to use the memento pattern to keep track of some properties that correspond to a file reading class. In this way we'll construct a flexible mechanism for moving back and forth between file lines.

With the preliminaries out of our way, let's continue exploring the capacities offered by the memento pattern. Let's get started!



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

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- 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...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: