验证中...
本周日【珠海源创会】一起聊聊:PingCAP分布式事务、支付宝移动端实践、GSBN技术框架选型,点此报名占座
片段 1 片段 2 片段 3 片段 4
originator.cs
原始数据 复制代码
class Originator
{
private string state;
public string State
{
get { return this.state; }
set { this.state = value; }
}
public Memento CreateMemento()
{
return new Memento(this.state);
}
public void SetMemento(Memento theMemento)
{
this.state = theMemento.State;
}
public void Show()
{
Console.WriteLine("state={0}",this.state);
}
}
memento.cs
原始数据 复制代码
class Memento
{
private string state;
public string State
{
get { return this.state; }
set { this.state = value; }
}
public Memento(string state)
{
this.state = state;
}
}
caretaker.cs
原始数据 复制代码
class Caretaker
{
private Memento memento;
public Memento Memento
{
get { return this.memento; }
set { this.memento = value; }
}
}
program.cs
原始数据 复制代码
class Program
{
static void Main(string[] args)
{
Originator theOriginator=new Originator();
theOriginator.State = "on";
theOriginator.Show();
Caretaker theCaretaker=new Caretaker();
theCaretaker.Memento = theOriginator.CreateMemento();
theOriginator.State = "off";
theOriginator.Show();
theOriginator.SetMemento(theCaretaker.Memento);
theOriginator.Show();
Console.ReadKey();
}
}

评论列表( 0 )

你可以在登录后,发表评论

搜索帮助

12_float_left_people 12_float_left_close