Last active
July 11, 2016 09:10
There Are Only Two Roles of Code 1
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 Calculator | |
{ | |
private readonly IStorageService storageService; | |
private List<int> history = new List<int>(); | |
private int sessionNumber = 1; | |
private bool newSession; | |
public Calculator(IStorageService storageService) | |
{ | |
this.storageService = storageService; | |
} | |
public int Add(int firstNumber, int secondNumber) | |
{ | |
if(newSession) | |
{ | |
sessionNumber++; | |
newSession = false; | |
} | |
var result = firstNumber + secondNumber; | |
history.Add(result); | |
return result; | |
} | |
public List<int> GetHistory() | |
{ | |
if (storageService.IsServiceOnline()) | |
return storageService.GetHistorySession(sessionNumber); | |
return new List<int>(); | |
} | |
public int Done() | |
{ | |
if (storageService.IsServiceOnline()) | |
{ | |
foreach(var result in history) | |
storageService.Store(result, sessionNumber); | |
} | |
newSession = true; | |
return sessionNumber; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment