static void Main(string[] args) { IElectronicDevice tv; var remote = TvRemote.GetDevice(DeviceType.TV); PowerButton pb = new PowerButton(remote); pb.Execute(); pb.Execute(); for (int i = 0; i < 30; i++) { pb.Volup(); } pb.Undo(); }
static void Main(string[] args) { Vehicle buick = new Vehicle("Buick", 160, 4); if (buick is IDrivable) { buick.Move(); buick.Stop(); } else { Console.WriteLine($"The {buick.Brand} can't driven"); } IElectronicDevice TV = TVRemote.GetDevice(); PowerButton powButt = new PowerButton(TV); powButt.Execute(); powButt.Undo(); }
static void Main(string[] args) { // Create a Vehicle object Vehicle buick = new Vehicle("Buick", 4, 160); // Check if Vehicle implements // IDrivable if (buick is IDrivable) { buick.Move(); buick.Stop(); } else { Console.WriteLine("The {0} can't be driven", buick.Brand); } // We are now modeling the act of // picking up a remote, aiming it // at the TV, clicking the power // button and then watching as // the TV turns on and off // Pick up the TV remote IElectronicDevice TV = TVRemote.GetDevice(); // Create the power button PowerButton powBut = new PowerButton(TV); // Turn the TV on and off with each // press powBut.Execute(); powBut.Undo(); Console.ReadLine(); }