In many cases, we have changed a lot of things. But I started regret. Maybe this is the weakness of humanity. Anyway, life is unable to return home. However, the software can be, because all operational programs are loaded in memory. So even if it changed, we can also have a way back to the origin. I think you may have already guessed what I want to say? Yes. MEMENTO mode. A simple pattern. // Original object public class originator {
public int number; public object myObject = null; private Memento myMemobject; public Originator () {} public Memento MemObject {get {return new Memento (this);} set {myMemobject = value; this.number = myMemobject.Number; this. MyObject = mymemobject.o;}}}
// Memory point [Serializable] Private class memento: iSerializable {
PRIVATE INT NUMBER;
Private Object o = null;
Public Memento (Originator O) {
Number = o.Number; o = o.myObject;
}
}
// Calling an instance public class client {public static int main (string [] args) {Originator o = new originator (); memento m = o.MemObject; // change value = 100; o.myObject = "Object "; // Restore o.MemObject = m; return 0;}}}
The value of Number and Object in Originator is stored in Memento. By calling the Number and Object values in Originator, the attribute method can be recovered. This satisfies the object-oriented principle.