Add basic memento pattern

This commit is contained in:
Petrutiu Mihai
2016-06-23 20:43:37 +03:00
parent 0a130b0405
commit 37151a23c7
10 changed files with 210 additions and 28 deletions

View File

@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace MememntoPattern.Employee
{
public class EmployeeExample
{
public void Run()
{
Caretaker caretaker = new Caretaker();
Employee e = new Employee();
e.Name = "Ghiuri";
e.Address = "Stairway to heaven";
Console.WriteLine("First saved address: {0}", e.Address);
caretaker.Save(e);
e.Address = "Highway to hell";
Console.WriteLine("Last saved address: {0}", e.Address);
caretaker.Save(e);
e.Address = "Home of the brave"; // No save, no home, no address
Console.WriteLine("Address before revert: {0}", e.Address);
caretaker.Revert(e);
Console.WriteLine("First reverted Address: {0}", e.Address);
caretaker.Revert(e);
Console.WriteLine("Second reverted Address: {0}", e.Address);
}
}
}