Skip to content

Instantly share code, notes, and snippets.

@alimozdemir
Last active August 30, 2018 11:33
Show Gist options
  • Save alimozdemir/cc3ea8fc1f7b002d5ef7870af859ec6a to your computer and use it in GitHub Desktop.
Save alimozdemir/cc3ea8fc1f7b002d5ef7870af859ec6a to your computer and use it in GitHub Desktop.
ActionHistory_V1 singleton pattern
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