Last active
August 29, 2015 14:27
-
-
Save rosalindwills/abb4072dc78e16f5d6b9 to your computer and use it in GitHub Desktop.
3b -- introducing an interface
This file contains hidden or 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 Adder { | |
private IRandomNumberGenerator _generator; | |
public Adder(IRandomNumberGenerator generator) { | |
_generator = generator; | |
} | |
public int AddTwoRandomNumbers() { | |
var firstInt = _generator.Generate(); | |
var secondInt = _generator.Generate(); | |
return firstInt + secondInt; | |
} | |
} | |
public interface IRandomNumberGenerator { | |
int Generate(); | |
} | |
public class RandomNumberGenerator : IRandomNumberGenerator { | |
public int Generate() { | |
Random rnd = new Random(); | |
return rnd.Next(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment