static void Main(string[] args) { var sensors = new List <ISensor>(); sensors.Add(SensorFactory.NewFireSensor("Lobby")); sensors.Add(SensorFactory.NewSmokeSensor("Bedroom")); sensors.Add(SensorFactory.NewMotionSensor("Bathroom")); var hazsensors = new List <ISensor>(); var secsensors = new List <ISensor>(); foreach (ISensor sensor in sensors) { if (sensor is IHazardSensor) { hazsensors.Add(sensor); } else { secsensors.Add(sensor); } } IControlUnit controlUnit = new ControlUnit(hazsensors); IControlUnit securityUnit = new SecurityControlUnit(secsensors); string input = string.Empty; while (!input.Equals("exit")) { Console.WriteLine("Type \"poll\" to poll all sensors once or \"exit\" to exit"); input = Console.ReadLine(); if (input.Equals("poll")) { controlUnit.PollSensors(); securityUnit.PollSensors(); } } }
public static void Main(string[] args) { List <ISensor> sensors = new List <ISensor>(); sensors.Add(new FireSensor("Room 1")); sensors.Add(new SmokeSensor("Room 2")); ControlUnit controlUnit = new ControlUnit(sensors); string input = string.Empty; while (!input.Equals("exit")) { Console.WriteLine("Type \"poll\" to poll all hazard sensors once or \"exit\" to exit"); input = Console.ReadLine(); if (input.Equals("poll")) { controlUnit.PollSensors(); } } List <ISensor> securitySensors = new List <ISensor>(); securitySensors.Add(new MotionSensor("Room 3")); securitySensors.Add(new HeatSensor("Room 4")); var securityControlUnit = new SecurityControlUnit(securitySensors); string inputTwo = string.Empty; while (!inputTwo.Equals("exit")) { Console.WriteLine("Type \"poll\" to poll all security sensors once or \"exit\" to exit"); inputTwo = Console.ReadLine(); if (inputTwo.Equals("poll")) { securityControlUnit.PollSensors(); } } }