title: Java - Memento pattern and Undo
body: <p>I am implementing an undo/redo function which requires me to use memento pattern.</p>
  
  <p>The flow of the partial program : "...the program then store the previous Vector using Memento Pattern, then the newly created object will be added to the Vector. After that, user may choose a show command to show what is inside the Vector, he can also enter undo command to restore, the undo can be repeated until it is restored to the original state..."</p>
  
  <p>From my research, I know there will be an originator, memento and caretaker.</p>
  
  <p>Here's my caretaker program</p>
  
  <pre><code>public class CareTaker {
        private Memento m;
        private Stack s;
        private Vector v;
        // Some of the implementation are not shown
  
        public void create() {
              // Some of the implementation are not shown
              // Assuming Vector is named "v"
              // Passing Vector to memento
              m = new Memento(v);
              s.add(m);
        }
        public void undo() {
            v = s.pop().restore();
        }
  }
  public class Memento {
      private Vector _v;
      public Memento(Vector v) {
        _v = v;
      }
      public Vector restore() {
        return _v;
      }
  }
  </code></pre>
  
  <p>Unfortunately , I failed to identify the "Originator" nor I know which one will be.
  Is this code fragment ever a correct Memento pattern if there is no Originator? </p>