public static void Main(string[] args) { // Whip up a receiver (the light bulb) LightBulbReceiver myLamp = new LightBulbReceiver(); // Whip up some commands and pass the receiver so the commands // know which light bulb to change. LightOnCommand on = new LightOnCommand(myLamp); LightOffCommand off = new LightOffCommand(myLamp); LightHalfwayCommand half = new LightHalfwayCommand(myLamp); LightDuskCommand dusk = new LightDuskCommand(myLamp); // Create the remote and attach the commands to each button Remote remote = new Remote(on, // circle off, // square half, // triangle dusk /* ex */); remote.PressCircleButton(); Console.WriteLine(myLamp.Brightness); remote.PressSquareButton(); Console.WriteLine(myLamp.Brightness); remote.PressTriangleButton(); Console.WriteLine(myLamp.Brightness); remote.PressExButton(); Console.WriteLine(myLamp.Brightness); /* Event Handler reminder * // "Press" some buttons, could do this using a UI. Not sure how * // to convert a console project to a UI, or if it's even possible. * ButtonPresser presser = new ButtonPresser(); * presser.CircleButtonPressed += remote.CircleButtonPressed; * presser.PressCircleButton(); */ }
public LightDuskCommand(LightBulbReceiver l) : base(l) { }
public LightOffCommand(LightBulbReceiver l) : base(l) { }
public LightHalfwayCommand(LightBulbReceiver l) : base(l) { }
// Setting the constructor to protected allows // you to call base() in child constructors protected LightBulbCommand(LightBulbReceiver l) { light = l; }