Select Page



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         }  }  

About The Author

Cédric Walter

I worked with various Insurances companies across Switzerland on online applications handling billion premium volumes. I love to continuously spark my creativity in many different and challenging open-source projects fueled by my great passion for innovation and blockchain technology.In my technical role as a senior software engineer and Blockchain consultant, I help to define and implement innovative solutions in the scope of both blockchain and traditional products, solutions, and services. I can support the full spectrum of software development activities, starting from analyzing ideas and business cases and up to the production deployment of the solutions.I'm the Founder and CEO of Disruptr GmbH.