Created
April 26, 2016 15:09
-
-
Save zs40x/82e7d2cb920c654178f29cfab8982e76 to your computer and use it in GitHub Desktop.
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
namespace Open_Closed_Principle.Violation | |
{ | |
public class AvgTemperatureReader | |
{ | |
public double GetAverageTemperature(List<object> temperatureSensors) | |
{ | |
double total = 0; | |
int count = 0; | |
foreach (var temperatureSensor in temperatureSensors.OfType<IndoorTemperatureSensor>()) | |
{ | |
total += (temperatureSensor).CurrentTemperature.Value; | |
count ++; | |
} | |
foreach (var temperatureSensor in temperatureSensors.OfType<OutdoorTemperatureSensor>()) | |
{ | |
total += (temperatureSensor).CurrentTemperature.Value; | |
count++; | |
} | |
if (count == 0) | |
return 0; | |
return total / count; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment