public void ConsumeElectricity(double electricity) { if (electricity <= MaxElectricityAllowed) { _electricalDevice.ConsumeElectricity(electricity); } }
static void Main(string[] args) { IKernel kernel = new StandardKernel(new BuildingManagerModule()); IElectricalDevice consumer = kernel.Get <IElectricalDevice>(BuildingManagerModule.HighElectricityDefenderName); consumer.ConsumeElectricity(5); Console.WriteLine("-------------"); Console.WriteLine(consumer); Console.WriteLine("-------------"); consumer.ConsumeElectricity(200); Console.WriteLine("-------------"); Console.WriteLine(consumer); Console.WriteLine("-------------"); }
public void ConsumeElectricity(double electricity) { double electricityToPass = electricity; if (electricityToPass > 0) { ReservedCapacity = Math.Min(ReservedCapacity + electricityToPass, MaxReservedCapacity); } else if (ReservedCapacity > 0) { electricityToPass = Math.Min(PassedElectricity, ReservedCapacity); ReservedCapacity -= electricityToPass; } _electricalDevice.ConsumeElectricity(electricityToPass); }