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.Valid | |
{ | |
public class AvgTemperatureReader | |
{ | |
public double GetAverageTemperature(List<ITemperatureSensor> sensors) | |
{ | |
return sensors.Count == 0 ? 0 : sensors.Average(s => s.CurrentTemperature.Value); | |
} | |
} | |
} |
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 Sensor | |
{ | |
public string Name { get; } | |
public List<double> MeasuredValues { get; } | |
public double AverageValue | |
=> MeasuredValues.Average(); | |
public double MinimumValue | |
=> MeasuredValues.Min(); | |
public double MaximumValue | |
=> MeasuredValues.Max(); |
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 Sensor | |
{ | |
public string Name { get; } | |
public List<double> MeasuredValues { get; } | |
public double AverageValue | |
=> MeasuredValues.Average(); | |
public double MinimumValue | |
=> MeasuredValues.Min(); | |
public double MaximumValue | |
=> MeasuredValues.Max(); |
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
[TestFixture] | |
public class Valid | |
{ | |
[Test] | |
public void TestReportGeneration() | |
{ | |
var sensorName = "TempSensor 1"; | |
var fileName = "FileName.txt"; | |
var sensor = new Sensor(sensorName, new List<double>() { 1.0D }); |
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
[TestFixture] | |
public class Valid | |
{ | |
[Test] | |
public void TestReportGeneration() | |
{ | |
var sensorName = "TempSensor 1"; | |
var sensor = new Sensor(sensorName, new List<double>() { 1.0D }); | |
var expectedContent = |
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
var sensorValid = | |
new Valid.Sensor("TemSensor 2", new List<double> { 12.4D, 77.2D, 88.1D }); | |
var reportGenerator = | |
new Valid.SensorReportGenerator( | |
new FileSystem(), | |
new PlainTextSensorReportGenerator(sensorValid) | |
); | |
reportGenerator.GenerateAndStoreReport("Report_2.txt"); |
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 ImmutableList<T> { | |
private let listItems: [T] | |
init() { | |
self.listItems = [T]() | |
} | |
init(listItems: [T]) { | |
self.listItems = listItems | |
} |
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 List<T> { | |
private let listItems: [T] | |
init() { | |
self.listItems = [T]() | |
} | |
init(listItems: [T]) { | |
self.listItems = listItems | |
} |
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
guard let settingsURL = URL.init(string: UIApplicationOpenSettingsURLString) else { return } | |
guard UIApplication.shared.canOpenURL(settingsURL) else { return } | |
UIApplication.shared.open(settingsURL, completionHandler: nil ) |