Add to MyYahoo!
Subscribe in NewsGator Online
Add to Newsburst
Add to Google
Add to My AOL
Add to Pluck
Subscribe in FeedLounge
Add to Windows Live
Add to NetVibes
Subscribe in Rojo
Subscribe in Bloglines
Add to MyMSN
Add to Plusmo for your cellphone
Add to PageFlakes
Add to Technorati
Add to BlinkBits
Memento Print E-mail
User Rating: / 1
PoorBest 
Thursday, 20 January 2005 21:45
Without violating encapsulation, capture and externalize an object's internal state so that the object can be restored to this state later.




Source code

/**
 * Creates a memento containing a snapshot of its current internal state.
 * Uses the memento to restore its internal state.
 * @role __Originator
 */
public class Originator {
        public Memento createMemento() {
                return new ConcreteMemento(this);        }

        public void setMemento(Memento memento) {
                if (memento instanceof ConcreteMemento) {
                        // extract state from memento
                }
        }

}

/**
 * Represents narrow interface of the memento visible to Caretaker
 * @role __Memento
 */
public interface Memento {
}

/**
 * Stores internal state of the Originator object. 
 * This is sort of wide memento interface,
 * visible to Originator.
 */
public class ConcreteMemento implements Memento {
        public ConcreteMemento(Originator originator) {
                // initialize memento with originator's state
        }

}

Comments
Add New Search RSS
Write comment
Name:
Email:
 
Title:
UBBCode:
[b] [i] [u] [url] [quote] [code] [img] 
 
:):grin;)8):p:roll:eek:upset:zzz:sigh:?:cry
:(:x
Please input the anti-spam code that you can read in the image.

3.20 Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved."

Last Updated ( Friday, 17 June 2005 23:40 )
 


Another articles:


Content View Hits : 2641551

Enter Amount: