forked from exceptionnotfound/DesignPatterns
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
36 lines (31 loc) · 1.09 KB
/
Copy pathProgram.cs
File metadata and controls
36 lines (31 loc) · 1.09 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Memento
{
class Program
{
/// <summary>
/// In the Memento pattern, we need to capture and externalize an object's state so that the object can be
/// restored to that state at a later time. A good example of this is undo/redo operations.
/// </summary>
/// <param name="args"></param>
static void Main(string[] args)
{
//Here's a new supplier for our restaurant
FoodSupplier s = new FoodSupplier();
s.Name = "Harold Karstark";
s.Phone = "(482) 449-1172";
// Let's store that entry in our database.
SupplierMemory m = new SupplierMemory();
m.Memento = s.SaveMemento();
// Continue changing originator
s.Address = "548 S Main St. Nowhere, KS";
// Crap, gotta undo that entry, I entered the wrong address
s.RestoreMemento(m.Memento);
Console.ReadKey();
}
}
}