forked from WeihanLi/DesignPatterns
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrototype.cs
More file actions
39 lines (32 loc) · 707 Bytes
/
Prototype.cs
File metadata and controls
39 lines (32 loc) · 707 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System;
namespace MementoPattern
{
/// <summary>
/// 发起人
/// </summary>
internal class Originator
{
public string State { get; set; }
public Memento CreateMemento()
{
return new Memento(State);
}
public void SetMemento(Memento memento)
{
State = memento?.State;
}
public void Show()
{
Console.WriteLine($"State:{State}");
}
}
internal class Memento
{
public string State { get; }
public Memento(string state) => State = state;
}
internal class Caretaker
{
public Memento Memento { get; set; }
}
}