/// <summary> /// The Single Responsibility principle states that a class should have only one reason to change. In the below, the SensorReader has two responsibilities, namely reading a sensor value and reporting it to a log. /// </summary> private static void Main() { SensorReader sensorReader = new SensorReader(); string sensorValue = sensorReader.ReadSensorValue(); sensorReader.WriteSensorValueToLog(sensorValue); }
/// <summary> /// The best solution to the SensorReader's multiple responsibilities is to simply seperate them. /// </summary> private static void Main() { // Separating the concerns is better: SensorReader sensorReader = new SensorReader(); string sensorValue = sensorReader.ReadSensorValue(); FileLogger filelOgger = new FileLogger(); filelOgger.WriteToLog(sensorValue); }
public string ReadSensorValue() { // simple pass-through return(sensorReader.ReadSensorValue()); }