static void Main(string[] args) { Vehicle buick = new Vehicle("Buick", 4, 180); Vehicle dacia = new Vehicle("Dacia"); if (buick is IDrivable) { buick.Move(); buick.Stop(); } else { Console.WriteLine("The {0} can't be driven.", buick.Brand); } if (dacia is IDrivable) { dacia.Move(); dacia.Stop(); } else { Console.WriteLine("The {0} can't be driven.", dacia.Brand); } IElectronicDevice TV = TVRemote.GetDevice(); PowerButtoon powBut = new PowerButtoon(TV); powBut.Execute(); TV.VolumeUp(); TV.VolumeDown(); powBut.Undo(); }
static void Main(string[] args) { Vehicle Chevy = new Vehicle("Chevy", 4, 170); // checking to see if the object will implement the interface if (Chevy is IDrivable) { Chevy.Move(); Chevy.Stop(); } else { Console.WriteLine($"The {0} be driver"); } IElectronicDevice TV = TVRemote.GetDevice(); PowerButton PowBut = new PowerButton(TV); PowBut.Excecute(); PowBut.Undo(); PowBut.Excecute(); VolumeButton VolBut = new VolumeButton(TV); VolBut.Excecute(); VolBut.Undo(); }
static void Main(string[] args) { Vehicle v1 = new Vehicle("Buick", 4, 160); if (v1 is IDrivable) { v1.Move(); v1.Stop(); } else { Console.WriteLine("the {0} can't be driven", v1.Brand); } //------------------------------------------------------------------------------ //picking up the TV remote IElectronicDevice TV = TVRemote.GetDevice(); //create the power button PowerButton pb = new PowerButton(TV); //turn the TV on and off with each press pb.Execute(); pb.Undo(); Console.ReadLine(); }
static void Main(string[] args) { Vehichle buick = new Vehichle("Buick", 4, 160); if (buick is IDrivable) { buick.Move(); buick.Stop(); } else { Console.WriteLine("The {0} can't be driven", buick.Brand); } IElectronicDevice TV = TVRemote.GetDevice(); PowerButton powBut = new PowerButton(TV); powBut.Execute(); powBut.Undo(); VolumeButton volBut = new VolumeButton(TV); volBut.Execute(); volBut.Undo(); Console.ReadLine(); }
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(); }
static void Main(string[] args) { Vehicle ford = new Vehicle("Ford", 4, 80); if (ford is IDrivable) { ford.Move(); ford.Stop(); } else { Console.WriteLine($"The {ford.Brand} cannot be driven"); } // Pick up Remote IElectronicDevice TV = TVRemote.GetDevice(); // Next create power button PowerButton powerButton = new PowerButton(TV); // Turn TV On and Off powerButton.Execute(); TV.VolumeUp(); TV.VolumeUp(); TV.VolumeUp(); TV.VolumeUp(); TV.VolumeDown(); TV.VolumeDown(); powerButton.Undo(); Console.ReadLine(); }
public static void RunCommand() { IElectronicDevice newDevice = TVRemote.getDevice(); TurnTVOn onCommand = new TurnTVOn(newDevice); DeviceButton onPressed = new DeviceButton(onCommand); onPressed.Press(); // ------- TurnTVOff offCommand = new TurnTVOff(newDevice); onPressed = new DeviceButton(offCommand); onPressed.Press(); // ------- TurnTVUp upCommand = new TurnTVUp(newDevice); onPressed = new DeviceButton(upCommand); onPressed.Press(); }
public static void EntryPoint() { IProgram2.Television television = new IProgram2.Television(); IElectronicDevice TV = TVRemote.GetDevice(); PowerButton pb = new PowerButton(TV); pb.Execute(); pb.Undo(); }
static void Main(string[] args) { Console.WriteLine("Hello World!"); IElectronicDevice TV = TVRemote.GetElectronicDevice(); PowerButton p = new PowerButton(TV); p.Execute(); p.Undo(); }
static void Main(string[] args) { //String name = Console.ReadLine(); // Console.WriteLine("Hi " + name + ". Please enter the hours of sleep"); // int number = int.Parse(Console.ReadLine()); // if (number > 10) // { // Console.WriteLine("You are getting enough sleep. Thank you"); // } // else // { // Console.WriteLine("You need enough sleep biko"); // } Gradebook gr = new ThrowAwayGradeBook();//bcos I inherited from the class Gradebook //delegates can call multiple methods and also u can multi cast or simply just add delegates by using += // gr.Namechanged = new NameChangedDelegate(OnNameChanged); gr.Namechanged += new NameChangedDelegate(OnNameChanged); gr.Namechanged += new NameChangedDelegate(OnNameChanged2); gr.Name = "Chidi's book"; gr.Name = "My new book"; gr.AddGrade(23); gr.AddGrade(89); gr.AddGrade(45); GradeStatistics stats = gr.ComputeStatistics(); Console.WriteLine("Average score is: " + stats.AverageGrade); Console.WriteLine("Lowest score is: " + stats.lowestGrade); Console.WriteLine("highest score is: " + stats.HighestGrade); using (StreamWriter output = File.CreateText(@"D:\grade.txt")) { gr.WriteGrades(output); } Vehicle mycar = new Vehicle("Benz", 4, 160); if (mycar is IDrivable) { mycar.Move(); mycar.Stop(); } else { Console.WriteLine($"The brand '{mycar.Brand}' cant be driven"); } IElectronicDevice TV = TVRemote.GetDevice(); PowerButton pwr = new PowerButton(TV); pwr.Execute(); TV.Off(); TV.VolumeUp(); TV.VolumeDown(); }
void OnEnable() { Debug.Log("------------------"); Debug.Log("COMMAND DESIGN PATTERN"); IElectronicDevice device = TVRemove.GetDevice(); TurnTVOn onCommand = new TurnTVOn(device); DeviceButton onPressed = new DeviceButton(onCommand); onPressed.Press(); // ----------------------- TurnTVOff offCommand = new TurnTVOff(device); onPressed = new DeviceButton(offCommand); onPressed.Press(); TurnVolumeUp volUpCommand = new TurnVolumeUp(device); onPressed = new DeviceButton(volUpCommand); onPressed.Press(); onPressed.Press(); onPressed.Press(); TurnVolumeDown volDownCommand = new TurnVolumeDown(device); onPressed = new DeviceButton(volDownCommand); onPressed.Press(); // ----------------------- Television tv = new Television(); Radio radio = new Radio(); List <IElectronicDevice> allDevices = new List <IElectronicDevice>(); allDevices.Add(tv); allDevices.Add(radio); TurnItAllOff turnOffDevices = new TurnItAllOff(allDevices); DeviceButton turnThemOff = new DeviceButton(turnOffDevices); turnThemOff.Press(); // ----------------------- turnThemOff.PressUndo(); // Homework for better Undo: // saving all commands in linked lists // on undo go through commands in list for undoing and do the opposite }
static void Main(string[] args) { IElectronicDevice TV = TVRemote.GetDevice(); PowerButton powerButton = new PowerButton(TV); VolumeButton volumeButton = new VolumeButton(TV); powerButton.Execute(); powerButton.Undo(); volumeButton.Execute(); volumeButton.Execute(); volumeButton.Undo(); }
static void Main(string[] args) { IElectronicDevice TV = TVRemote.GetElectronic(); PowerButton PowBtn = new PowerButton(TV); PowBtn.Execute(); PowBtn.Undo(); /*vehicle buick = new vehicle("Buick", 4, 190); * if(buick is vehicle) * { * buick.Move(); * buick.Stop(); * }*/ }
static void Main(string[] args) { Vehicle vh1 = new Vehicle("bmw", 4, 120); if (vh1 is IDrivable) { vh1.Move(); vh1.Stop(); } IElectronicDevice TV = TVRemote.GetDevice(); PowerButton powButton = new PowerButton(TV); powButton.Execute(); powButton.Undo(); }
static void Main(string[] args) { TVRemoteController pilot = new TVRemoteController(); IElectronicDevice TV = pilot.GetDevice(); PowerButton powBut = new PowerButton(TV); VolumeUpButton upBut = new VolumeUpButton(TV); VolumeDownButton downBut = new VolumeDownButton(TV); powBut.Execute(); downBut.Execute(); upBut.Execute(); Console.ReadLine(); }
void Start() { Debug.Log("------------------Command Pattern--------------"); IElectronicDevice device = TVRemove.GetDevice(); TurnTVOn onCommand = new TurnTVOn(device); DeviceButton onPressed = new DeviceButton(onCommand); onPressed.Press(); // ----------------------- TurnTVOff offCommand = new TurnTVOff(device); onPressed = new DeviceButton(offCommand); onPressed.Press(); TurnVolumeUp volUpCommand = new TurnVolumeUp(device); onPressed = new DeviceButton(volUpCommand); onPressed.Press(); onPressed.Press(); onPressed.Press(); TurnVolumeDown volDownCommand = new TurnVolumeDown(device); onPressed = new DeviceButton(volDownCommand); onPressed.Press(); // ----------------------- Television tv = new Television(); Radio radio = new Radio(); List <IElectronicDevice> allDevices = new List <IElectronicDevice>(); allDevices.Add(tv); allDevices.Add(radio); TurnItAllOff turnOffDevices = new TurnItAllOff(allDevices); DeviceButton turnThemOff = new DeviceButton(turnOffDevices); turnThemOff.Press(); // ----------------------- turnThemOff.PressUndo(); }
static void Interfaces() { // 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); VolumneButton volBut = new VolumneButton(TV); // Turn the TV on and off with each // press powBut.Execute(); powBut.Undo(); volBut.Execute(); volBut.Execute(); volBut.Execute(); volBut.Execute(); volBut.Undo(); volBut.Undo(); volBut.Undo(); volBut.Undo(); volBut.Undo(); }
static void Main(string[] args) { Vehicle buick = new Vehicle("Buick", 165, 4); if (buick is Vehicle) { buick.Move(); } else { Console.WriteLine($"The {buick.Brand} can't be Driven"); } IElectronicDevice TV = TVRemote.GetDevice(); PowerButton powBtn = new PowerButton(TV); powBtn.Execute(); powBtn.Undo(); }
public static void Sample(string[] args) { Vehicle Skoda = new Vehicle("Skoda", 4, 180); if (Skoda is IDrivable) { Skoda.Move(); Skoda.Stop(); } else { Console.WriteLine($"{Skoda.Brand} can't be drivable"); } IElectronicDevice TV = TVRemote.GetDevice(); PowerButton powBt = new PowerButton(TV); powBt.Execute(); powBt.Undo(); }
static void Main(string[] args) { Vehicle buick = new Vehicle("Buick", 4, 160); if (buick is IDrivable) { buick.Move(); buick.Stop(); } IElectronicDevice TV = TVRemote.GetDevice(); PowerButton powBut = new PowerButton(TV); powBut.Execute(); powBut.Undo(); Console.ReadLine(); }
static void Main(string[] args) { //Basic use of interface Vehicle buick = new Vehicle("Buick", 4, 120); //check if buick implements IDrivable //similar to checking if a class is an instance of a parent class if (buick is IDrivable) { buick.Move(); buick.Stop(); } else { Console.WriteLine("This {0} is not drivable", buick.Brand); } //MORE COMPLEX IMPLEMENTATION Console.WriteLine(); IElectronicDevice TV = TVRemote.GetDevice(); PowerButton powButton = new PowerButton(TV); powButton.Execute(); powButton.Undo(); Console.WriteLine(); IElectronicDevice TV2 = new Television(80); VolumeButton volButton = new VolumeButton(TV2); volButton.Execute(); volButton.Undo(); if (TV2 is IElectronicDevice) { powButton = new PowerButton(TV2); powButton.Undo(); } Console.ReadLine(); }
public static void FirstDemo() { IElectronicDevice newDevice = TvRemote.getDevice(); TurnTvOn onCommand = new TurnTvOn(newDevice); DeviceButton onPressed = new DeviceButton(onCommand); onPressed.Press(); TurnTvOff offcommand = new TurnTvOff(newDevice); onPressed = new DeviceButton(offcommand); onPressed.Press(); TurnTvUp upcommand = new TurnTvUp(newDevice); onPressed = new DeviceButton(upcommand); onPressed.Press(); onPressed.Press(); onPressed.Press(); }
private static void Sample2() { // 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(); TV.VolumeUp(); powBut.Undo(); }
private static void Part10(string[] args) { Vehicle buick = new Vehicle("Buick", 4, 65); if (buick is IDrivable) { buick.Move(); buick.Stop(); } else { Console.WriteLine("Not Drivable"); } IElectronicDevice TV = TVRemote.GetDevice(); PowerButton powerButton = new PowerButton(TV); powerButton.Execute(); powerButton.Undo(); }
static void Main(string[] args) { Vehicle buick = new Vehicle("Buick", 4, 160); if (buick is IDrivable) // checks to see if it is IDriveable { buick.Move(); buick.Stop(); } else { Console.WriteLine("{0} cannot be driven", buick.Brand); } IElectronicDevice TV = TVRemote.GetDevice(); PowerButton powBut = new PowerButton(TV); powBut.Execute(); powBut.Undo(); }
static void Main(string[] args) { IElectronicDevice newDevice = TVRemote.GetDevice(); ICommand onCommand = new TurnTVOn(newDevice); DeviceButton onPressed = new DeviceButton(onCommand); onPressed.press(); ICommand offCommand = new TurnTVOff(newDevice); onPressed = new DeviceButton(offCommand); onPressed.press(); ICommand volUpCommand = new TurnTVUp(newDevice); onPressed = new DeviceButton(volUpCommand); onPressed.press(); onPressed.press(); onPressed.press(); ICommand volDownCommand = new TurnTVDown(newDevice); onPressed = new DeviceButton(volDownCommand); onPressed.press(); // ---------------------------------- // Television theTV = new Television(); Radio theRadio = new Radio(); List <IElectronicDevice> allDevices = new List <IElectronicDevice>(); allDevices.Add(theTV); allDevices.Add(theRadio); TurnItAllOff turnOffDevices = new TurnItAllOff(allDevices); DeviceButton turnThemOff = new DeviceButton(turnOffDevices); turnThemOff.press(); }
static void Main(string[] args) { Vehicle buick = new Vehicle("Buick", 4, 160); if (buick is IDrivable) { buick.Move(); buick.Stop(); } else { Console.WriteLine($"The {buick.Brand} can not be driven!"); } IElectronicDevice TV = TVRemote.GetDevice(); PowerButton powerbutton = new PowerButton(TV); powerbutton.Execute(); powerbutton.Undo(); }
public static void Main() { Vehicle bike = new Vehicle("Bike", 4, 160); if (bike is IDrivable) { bike.Move(); bike.Stop(); } else { Console.WriteLine("The {0} can't be driven", bike.Brand); } IElectronicDevice TV = TVRemote.GetDevice(); PowerButton powBut = new PowerButton(TV); powBut.Execute(); powBut.Undo(); }
static void Main(string[] args) { IElectronicDevice TV = TVRemote.GetDevice(); PowerButton powbut = new PowerButton(TV); powbut.Execute(); powbut.Undo(); Television vol = new Television(80); if (vol is IElectronicDevice) { vol.VolumeUp(); vol.VolumeDown(); } else { Console.WriteLine("isnt electronic device"); } Console.ReadLine(); }
//This would be Main(string[] args) public void MainClass() { Vechicle buick = new Vechicle("Buick", 4, 160); if (buick is IDriveable) { buick.Move(); buick.Stop(); } else { Console.WriteLine("the {0} can't be driven", buick.Brand); } IElectronicDevice TV = TVRemote.GetDevice(); PowerButton powBut = new PowerButton(TV); powBut.Execute(); powBut.Undo(); Console.ReadLine(); }
public TvRemote(IElectronicDevice device) { _device = device; }
public TvTurnUpp(IElectronicDevice newDevice) { theDevice = newDevice; }
public TurnTvOnCommand(IElectronicDevice device) { _device = device; }
public TurnVolumeUp(IElectronicDevice device) { this.device = device; }
public TurnTvDown(IElectronicDevice newDevice) { theDevice = newDevice; }
public TurnTVOn(IElectronicDevice device) { this.device = device; }
public VolumeDownTvCommand(IElectronicDevice device) { _device = device; }
public TurnTvOff(IElectronicDevice newDevice) { theDevice = newDevice; }