Ejemplo n.º 1
0
        public object Clone()
        {
            var value = new OriginatorPrototype();

            value.state = state;
            return(value);
        }
Ejemplo n.º 2
0
        public static void main(String[] args)
        {
            OriginatorPrototype or = new OriginatorPrototype();
            PrototypeCaretaker  cr = new PrototypeCaretaker();

            or.SetState("S0");
            Console.WriteLine("初始状态:" + or.GetState());
            cr.SetMemento(or.CreateMemento()); //保存状态
            or.SetState("S1");
            Console.WriteLine("新的状态:" + or.GetState());
            or.RestoreMemento(cr.GetMemento()); //恢复状态
            Console.WriteLine("恢复状态:" + or.GetState());
        }
Ejemplo n.º 3
0
 public void SetMemento(OriginatorPrototype opt)
 {
     this.opt = opt;
 }
Ejemplo n.º 4
0
 public void RestoreMemento(OriginatorPrototype opt)
 {
     this.SetState(opt.GetState());
 }