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
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
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
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>()) |
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 LiskovSubstitutionPrinciple.Tests | |
{ | |
[TestFixture] | |
public class Violation | |
{ | |
[Test] | |
public void RectangleIsOkay() | |
{ | |
Rectangle rect = new Rectangle | |
{ |
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 LiskovSubstitutionPrinciple.Violation | |
{ | |
public class Rectangle | |
{ | |
protected int _width; | |
protected int _height; | |
public virtual int Height | |
{ | |
get { return _height; } |
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 Person | |
{ | |
public int Age { get; } | |
public string Name { get; } | |
public Person(int age, string name) | |
{ | |
this.Age = age; | |
this.Name = name; | |
} |
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 Program | |
{ | |
public static void Main(string[] args) | |
{ | |
PowerOf2Example(); | |
} | |
private static void PowerOf2Example() | |
{ | |
var numbers = new List<int>() {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; |
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 Engine | |
{ | |
public bool IsRunning { get; private set; } | |
public void Start() { } | |
public void Stop() { } | |
} | |
class Machine | |
{ | |
public Engine Engine { get; } |