CSDN博客

img 2002pine

Design Pattern 5-Memento

发表于2004/9/25 17:14:00  705人阅读

using System;

namespace Pattern
{
 /// <summary>
 /// Summary description for Class1.
 /// </summary>
 public class memento
 {
  public int number;   
  public string file = "";
  public memento(Originator m)
  {  
  number = m.number ;  
  file = m.file;
  }
 }
 public class Originator
 {   
  
 
  public int number;   
  public string file = "";  
  public Originator(){}  // 创建一个Memento 
  public memento getMemento(){    return new memento(this);}
    // 恢复到原始值  
  public void setMemento(memento m)
  {    
   number = m.number;  
      file = m.file;  
  }

 }
}

   //备忘录
  Originator o=new Originator();
  o.file ="old file";
   o.number =100;
 memento m=o.getMemento();

 o.file ="new file";
  o.number =2100;

 o.setMemento(m);
 Console.WriteLine(o.file);

阅读全文
0 0

相关文章推荐

img
取 消
img