-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCaretaker.cs
More file actions
27 lines (23 loc) · 755 Bytes
/
Caretaker.cs
File metadata and controls
27 lines (23 loc) · 755 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BehavioralPatterns.Memento
{
public class Caretaker
{
public static void Run()
{
IList<Memento> mementoes = new List<Memento>();
Originator originator = new Originator();
originator.SetState("State 1");
originator.SetState("State 2");
mementoes.Add(originator.Save()); // checkpoint 1
originator.SetState("State 3");
mementoes.Add(originator.Save()); // checkpoint 2
originator.SetState("State 4");
originator.Restore(mementoes[0]); // restore to checkpoint 1
}
}
}