备忘录模式
来源:互联网 发布:淘宝女鞋店推荐 编辑:程序博客网 时间:2024/04/30 04:58
/*
*
* User: Administrator
* Date: 2007-7-2
* Time: 9:02
*/
using System;
using System.Collections.Generic;
namespace myMemonto
{
public interface IMemonto{}
public class State
{
public State(){}
public string stateName;//状态名
public int Level;//状态级别
}
//发起者
public class Originator
{
private class Memonto:IMemonto
{
private State _state;
public Memonto(State st)
{
_state=new State();
_state.stateName=st.stateName;
_state.Level=st.Level;
}
public State state
{
get{
return _state;
}
set{
_state=value;
}
}
}
private State state;
public Originator()
{
state=new State();
state.stateName="begin";
state.Level=1;
}
public string StateName
{
get{return state.stateName;}
set{state.stateName=value;}
}
public int Level
{
get
{
return state.Level;
}
set
{
state.Level=value;
}
}
public IMemonto CreateMomento() {
return new Memonto(this.state);
}
public void SetState(IMemonto m)
{
Memonto mm=(Memonto)m;
this.state=mm.state;
}
}
public class Caretaker:System.Collections.CollectionBase
{
public Caretaker(){}
public int Add(IMemonto st)
{
return List.Add(st);
}
public IMemonto this[int index]{
get{
return (IMemonto)List[index];
}
set{
List[index]=value;
}
}
public void Remove(IMemonto st){
List.Remove(st);
}
public IMemonto Restore()
{
if(List.Count==0) return null;
IMemonto st=(IMemonto) List[List.Count-1];
List.Remove(st);
return st;
}
}
class MainClass
{
public static void Main(string[] args)
{
//Console.WriteLine("Hello World!");
Originator o=new Originator();
Caretaker c=new Caretaker();
c.Add(o.CreateMomento());
o.StateName="one";
o.Level=100;
c.Add(o.CreateMomento());
o.StateName="two";
o.Level=200;
c.Add(o.CreateMomento());
IMemonto m=c.Restore();
while(m!=null){
o.SetState(m);
System.Console.WriteLine(o.StateName);
m=c.Restore();
}
System.Console.ReadLine();
}
}
}
*
* User: Administrator
* Date: 2007-7-2
* Time: 9:02
*/
using System;
using System.Collections.Generic;
namespace myMemonto
{
public interface IMemonto{}
public class State
{
public State(){}
public string stateName;//状态名
public int Level;//状态级别
}
//发起者
public class Originator
{
private class Memonto:IMemonto
{
private State _state;
public Memonto(State st)
{
_state=new State();
_state.stateName=st.stateName;
_state.Level=st.Level;
}
public State state
{
get{
return _state;
}
set{
_state=value;
}
}
}
private State state;
public Originator()
{
state=new State();
state.stateName="begin";
state.Level=1;
}
public string StateName
{
get{return state.stateName;}
set{state.stateName=value;}
}
public int Level
{
get
{
return state.Level;
}
set
{
state.Level=value;
}
}
public IMemonto CreateMomento() {
return new Memonto(this.state);
}
public void SetState(IMemonto m)
{
Memonto mm=(Memonto)m;
this.state=mm.state;
}
}
public class Caretaker:System.Collections.CollectionBase
{
public Caretaker(){}
public int Add(IMemonto st)
{
return List.Add(st);
}
public IMemonto this[int index]{
get{
return (IMemonto)List[index];
}
set{
List[index]=value;
}
}
public void Remove(IMemonto st){
List.Remove(st);
}
public IMemonto Restore()
{
if(List.Count==0) return null;
IMemonto st=(IMemonto) List[List.Count-1];
List.Remove(st);
return st;
}
}
class MainClass
{
public static void Main(string[] args)
{
//Console.WriteLine("Hello World!");
Originator o=new Originator();
Caretaker c=new Caretaker();
c.Add(o.CreateMomento());
o.StateName="one";
o.Level=100;
c.Add(o.CreateMomento());
o.StateName="two";
o.Level=200;
c.Add(o.CreateMomento());
IMemonto m=c.Restore();
while(m!=null){
o.SetState(m);
System.Console.WriteLine(o.StateName);
m=c.Restore();
}
System.Console.ReadLine();
}
}
}
- 备忘录模式
- 备忘录模式
- 备忘录模式
- 备忘录模式
- 备忘录模式
- 备忘录模式
- 备忘录模式
- 备忘录模式
- 备忘录模式
- 备忘录模式
- 备忘录模式
- 备忘录模式
- 备忘录模式
- 备忘录模式
- 备忘录模式
- 备忘录模式
- 备忘录模式
- 备忘录模式
- Linux 常用命令
- Lantronix——SLM
- C#获取远程网页中的所有链接URL
- (第Ⅱ部分 创建型模式篇) 第2章 抽象工厂模式(Abstract Factory)
- 计算机专业英语名词解释
- 备忘录模式
- 【转载】软件测试的各个阶段的职业技能要求
- SQL Server 2008 -“Katmai ”
- 转贴:人生就像一碗汤
- 如何知道COM端口在使用中
- (第Ⅱ部分 创建型模式篇) 第3章 建造者模式(Builder Pattern)
- (第Ⅱ部分 创建型模式篇) 第4章 工厂方法(Factory Method)
- (第Ⅱ部分 创建型模式篇)第5章 原型模式(Protype Pattern)
- NET中文件下载