Last active
August 30, 2018 11:33
-
-
Save alimozdemir/cc3ea8fc1f7b002d5ef7870af859ec6a to your computer and use it in GitHub Desktop.
ActionHistory_V1 singleton pattern
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ActionHistory_V1 : IActionHistory | |
{ | |
private Stack<string> _history { get; set; } | |
public ActionHistory_V1() | |
{ | |
if (File.Exists("actions.txt")) | |
{ | |
var lines = File.ReadAllLines("actions.txt"); | |
_history = new Stack<string>(lines.ToList()); | |
} | |
else | |
_history = new Stack<string>(); | |
} | |
public void AddAction(string action) | |
{ | |
_history.Push(action); | |
} | |
public void Save() | |
{ | |
File.WriteAllLines("actions.txt", _history); | |
} | |
public string RetriveLastAction() | |
{ | |
return _history.FirstOrDefault(); | |
} | |
public List<string> RetriveAllActions() | |
{ | |
return _history.ToList(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment