PHP
  Home arrow PHP arrow Introducing the Memento Pattern
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 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
JMSL Numerical Library 
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

Introducing the Memento Pattern
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 5
    2007-01-08

    Table of Contents:
  • Introducing the Memento Pattern
  • Creating the first piece of the memento pattern
  • Building the second piece of the memento pattern
  • Implementing the memento 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


    Introducing the Memento Pattern


    (Page 1 of 4 )

    PHP developers frequently need to maintain the state of an object across several web pages. There are a number of ways to do this. In this article, the first of two parts, you will learn how to handle this task with the memento pattern.

    Introduction

    As the seasoned PHP developer that you certainly are, you'll probably know that one of the easiest ways to track and maintain the state of several variables across different HTTP requests is by using the neat capabilities of sessions. These have been included for a long time with the different PHP distributions.

    Moving toward PHP object-oriented programming, it's easy to maintain the state of a certain object across several web pages because a single instance of a class can be also stored onto a typical session variable.

    While the above mentioned process is one of the most common tasks that a PHP programmer has to tackle when developing a web application, it is fair to say that an object can also be tracked by using a design pattern. Logically, at this moment you're wondering: what pattern is capable of doing that? Well, I'm glad you asked, since the answer to your question is the memento pattern.

    To put it simply, when this pattern is used in the context of a given application, two classes are involved: the first one is called the originator, while the second one is denoted the caretaker. Despite the funny names assigned to these classes, which may lead one to think that this pattern is rather useless, the truth is that it can be pretty handy for holding the state of a particular class.

    In accordance with the schema of classes that I described a few lines above, the caretaker would be responsible for maintaining the state of the originator by using one or more methods. However, the implementation of this pattern is particularly interesting, since the caretaker object will keep track of the state of the originator by using only the interface of the originator.

    Does this definition sound confusing? Don't you worry about it for the moment, because in this two-part series, I'm going to demonstrate with numerous code samples how to apply the memento pattern so that it can be used within your own PHP applications with only minor problems.

    Having defined the goal of this new series, come with me and learn how to implement this useful pattern with PHP 5. Do we have a deal? Okay, let's get started.

    More PHP Articles
    More By Alejandro Gervasio


       · In this first part of this new series, the basics of the memento pattern are...
       · Great article - I really enjoyed this one!j
       · Hello Jon,Thank you for the kind comments on this PHP article. I really...
     

       

    PHP ARTICLES

    - Validating Web Forms with the Code Igniter P...
    - Output Buffering
    - Paginating Database Records with the Code Ig...
    - HTTP Headers in Web Development
    - Project Management: Administration
    - Building a Database-Driven Application with ...
    - User Authentication for a Project Management...
    - Introduction to the CodeIgniter PHP Framework
    - Adding Users for a Project Management Applic...
    - Migrating Class Code for a MIME Email to PHP...
    - Login and Logout Authentication for a Projec...
    - Composing Messages in HTML for MIME Email wi...
    - Project Management: Authentication
    - A Better Way to Determine MIME Types for MIM...
    - Project Management Overview





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway