Created
March 3, 2015 12:58
-
-
Save cakper/ef0c03bca0a2fb603e8e to your computer and use it in GitHub Desktop.
Statistics
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
class Statistics { | |
let minimum: Int | |
let maximum: Int | |
let average: Int | |
init(minimum: Int, maximum: Int, average: Int) { | |
self.minimum = minimum | |
self.maximum = maximum | |
self.average = average | |
} | |
} | |
protocol MinimumCalculator { | |
func calculate(input: [Int]) -> Int | |
} | |
protocol MaximumCalculator { | |
func calculate(input: [Int]) -> Int | |
} | |
protocol AverageCalculator { | |
func calculate(input: [Int]) -> Int | |
} | |
class Stats { | |
let minimumCalculator: MinimumCalculator | |
let maximumCalculator: MaximumCalculator | |
let averageCalculator: AverageCalculator | |
init(minimumCalculator: MinimumCalculator, maximumCalculator: MaximumCalculator, averageCalculator: AverageCalculator) { | |
self.minimumCalculator = minimumCalculator | |
self.maximumCalculator = maximumCalculator | |
self.averageCalculator = averageCalculator | |
} | |
func calculate(input: [Int]) -> Statistics { | |
return Statistics( | |
minimum: self.minimumCalculator.calculate(input), | |
maximum: self.maximumCalculator.calculate(input), | |
average: self.averageCalculator.calculate(input) | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment