title: memento pattern - restore complex object in a memento (JAVA)
body: <p>Thank you for reading this question. Please help me to solve this complex issue.</p>
  
  <p>Here is the situation:</p>
  
  <p>Oringator holds a object to execute some method.</p>
  
  <p>Memento pattern needs to backup the complex object state in oringator.How?</p>
  
  <p>Example code:</p>
  
  <p><a href="http://pastebin.com/4rV2aw3B" rel="nofollow">http://pastebin.com/4rV2aw3B</a></p>
  
  <p>The problem is , java does pass by value, do not pass by reference.
  But it is a bit tricky for object passing.
  If I passed an object into the method, although the method holds a new memeory address of object,the memory address is still pointing to the same object which is passed in. 
  See this example:
  <a href="http://www.javaworld.com/javaqa/2000-05/03-qa-0526-pass.html" rel="nofollow">http://www.javaworld.com/javaqa/2000-05/03-qa-0526-pass.html</a></p>
  
  <p>If I create the memento and pass the object to the new memento object, the memento object still holds the orignal complex object(which is needed to backup).</p>
  
  <p>So, how to create the memento pattern for backup the complex object which is in command pattern?</p>
  
  <p>Thank you.</p>