public static void Start() { var remoteControl = new RemoteControl(); var light = new Light(); var lightOn = new LightOnCommand(light); var lightOff = new LightOffCommand(light); var stereo = new Stereo(); var stereoOn = new StereoOnCommand(stereo); var stereoOff = new StereoOffCommand(stereo); var ceililngFan = new CeilingFan("Kitchen room"); var ceililngFanLowOn = new CeilingFanOnCommand(ceililngFan, CeilingFanSpeed.Low); var ceililngFanMediumOn = new CeilingFanOnCommand(ceililngFan, CeilingFanSpeed.Medium); var ceililngFanHighOn = new CeilingFanOnCommand(ceililngFan, CeilingFanSpeed.High); var ceililngFanOff = new CeilingFanOffCommand(ceililngFan); var partyOn = new MacroCommand(new ICommand[] { lightOn, stereoOn }); var partyOff = new MacroCommand(new ICommand[] { lightOff, stereoOff }); remoteControl.SetCommand(2, lightOn, lightOff); remoteControl.SetCommand(3, stereoOn, stereoOff); remoteControl.SetCommand(4, ceililngFanLowOn, ceililngFanOff); remoteControl.SetCommand(5, ceililngFanMediumOn, ceililngFanOff); remoteControl.SetCommand(6, ceililngFanHighOn, ceililngFanOff); remoteControl.SetCommand(1, partyOn, partyOff); remoteControl.P(); RemoteControlPressButtons(remoteControl); }
public static void Run() { var remoteControl = new RemoteControl(); var livingRoomLight = new Light("Living Room"); var kitchenLight = new Light("Kitchen"); var ceilingFan = new CeilingFan("Living Room"); var garageDoor = new GarageDoor(""); var stereo = new Stereo("Living Room"); var livingRoomLightOn = new LightOnCommand(livingRoomLight); var livingRoomLightOff = new LightOffCommand(livingRoomLight); var kitchenLightOn = new LightOnCommand(kitchenLight); var kitchenLightOff = new LightOffCommand(kitchenLight); var ceilingFanOn = new CeilingFanOnCommand(ceilingFan); var ceilingFanOff = new CeilingFanOffCommand(ceilingFan); var garageDoorUp = new GarageDoorUpCommand(garageDoor); var garageDoorDown = new GarageDoorDownCommand(garageDoor); var stereoOnWithCD = new StereoOnWithCDCommand(stereo); var stereoOff = new StereoOffCommand(stereo); remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff); remoteControl.SetCommand(1, kitchenLightOn, kitchenLightOff); remoteControl.SetCommand(2, ceilingFanOn, ceilingFanOff); remoteControl.SetCommand(3, stereoOnWithCD, stereoOff); Console.WriteLine(remoteControl); Console.WriteLine(); remoteControl.OnButtonWasPushed(0); Console.WriteLine(); remoteControl.OffButtonWasPushed(0); Console.WriteLine(); remoteControl.OnButtonWasPushed(1); Console.WriteLine(); remoteControl.OffButtonWasPushed(1); Console.WriteLine(); remoteControl.OnButtonWasPushed(2); Console.WriteLine(); remoteControl.OffButtonWasPushed(2); Console.WriteLine(); remoteControl.OnButtonWasPushed(3); Console.WriteLine(); remoteControl.OffButtonWasPushed(3); }
private static string ProcessRemoteControl() { RemoteControl remoteControl = new RemoteControl(); Light livingRoomLight = new Light("Living Room"); Light kitchenLight = new Light("Kitchen"); CeilingFan ceilingFan = new CeilingFan("Living Room"); GarageDoor garage = new GarageDoor(); Stereo stereo = new Stereo(); LightOnCommand livingRoomLightOn = new LightOnCommand(livingRoomLight); LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight); LightOnCommand kitchenLightOn = new LightOnCommand(kitchenLight); LightOffCommand kitchenLightOff = new LightOffCommand(kitchenLight); CeilingFanOnCommand ceilingFanOnCommand = new CeilingFanOnCommand(ceilingFan); CeilingFanOffCommand ceilingFanOffCommand = new CeilingFanOffCommand(ceilingFan); GarageDoorOpenCommand garageDoorOpen = new GarageDoorOpenCommand(garage); GarageDoorCloseCommand garageDoorClose = new GarageDoorCloseCommand(garage); StereoOnWithCDCommand stereoOnWithCDCommand = new StereoOnWithCDCommand(stereo); StereoOffCommand stereoOffCommand = new StereoOffCommand(stereo); remoteControl.OnCommands[0] = livingRoomLightOn; remoteControl.OnCommands[1] = kitchenLightOn; remoteControl.OnCommands[2] = ceilingFanOnCommand; remoteControl.OnCommands[3] = stereoOnWithCDCommand; remoteControl.OffCommands[0] = livingRoomLightOff; remoteControl.OffCommands[1] = kitchenLightOff; remoteControl.OffCommands[2] = ceilingFanOffCommand; remoteControl.OffCommands[3] = stereoOffCommand; StringBuilder sb = new StringBuilder(); sb.AppendLine(remoteControl.ToString()); sb.AppendLine(remoteControl.OnButtonWasPushed(0)); sb.AppendLine(remoteControl.OffButtonWasPushed(0)); sb.AppendLine(remoteControl.OnButtonWasPushed(1)); sb.AppendLine(remoteControl.OffButtonWasPushed(1)); sb.AppendLine(remoteControl.OnButtonWasPushed(2)); sb.AppendLine(remoteControl.OffButtonWasPushed(2)); sb.AppendLine(remoteControl.OnButtonWasPushed(3)); sb.AppendLine(remoteControl.OffButtonWasPushed(3)); return(sb.ToString()); }
public static void CommandExample() { Light livingRoomLight = new Light("Living Room"); Light kitchenLight = new Light("Kitchen"); CeilingFan ceilingFan = new CeilingFan("Living Room"); GarageDoor garageDoor = new GarageDoor(""); Stereo stereo = new Stereo("Living Room"); LightOnCommand livingRoomLightOn = new LightOnCommand(livingRoomLight); LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight); LightOnCommand kitchenLightOn = new LightOnCommand(kitchenLight); LightOffCommand kitchenLightOff = new LightOffCommand(kitchenLight); CeilingFanOnCommand ceilingFanOn = new CeilingFanOnCommand(ceilingFan); CeilingFanOffCommand ceilingFanOff = new CeilingFanOffCommand(ceilingFan); GarageDoorUpCommand garageDoorUp = new GarageDoorUpCommand(garageDoor); GarageDoorDownCommand garageDoorDown = new GarageDoorDownCommand(garageDoor); StereoOnWithCDCommand stereoOnWithCD = new StereoOnWithCDCommand(stereo); StereoOffCommand stereoOff = new StereoOffCommand(stereo); RemoteControl remoteControl = new RemoteControl(); remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff); remoteControl.SetCommand(1, kitchenLightOn, kitchenLightOff); remoteControl.SetCommand(2, ceilingFanOn, ceilingFanOff); remoteControl.SetCommand(3, stereoOnWithCD, stereoOff); Console.WriteLine(remoteControl.ToString()); remoteControl.OnButtonPushed(0); remoteControl.OffButtonPushed(0); remoteControl.OnButtonPushed(1); remoteControl.OffButtonPushed(1); remoteControl.OnButtonPushed(2); remoteControl.OffButtonPushed(2); remoteControl.OnButtonPushed(3); remoteControl.OffButtonPushed(3); }
public void TestTurningOn()//Command Pattern Client { //Command Pattern Invoker Remote remote = new Remote(); Light livingRoomLight = new Light("Living Room"); Light kitchenLight = new Light("Kitchen"); CeilingFan ceilingFan = new CeilingFan("Living Room"); GarageDoor garageDoor = new GarageDoor(""); Stereo stereo = new Stereo("Living Room"); LightOnCommand livingRoomLightOn = new LightOnCommand(livingRoomLight); LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight); LightOnCommand kitchenLightOn = new LightOnCommand(kitchenLight); LightOffCommand kitchenLightOff = new LightOffCommand(kitchenLight); CeilingFanOnCommand ceilingFanOn = new CeilingFanOnCommand(ceilingFan); CeilingFanOffCommand ceilingFanOff = new CeilingFanOffCommand(ceilingFan); GarageDoorUpCommand garageDoorUp = new GarageDoorUpCommand(garageDoor); GarageDoorDownCommand garageDoorDown = new GarageDoorDownCommand(garageDoor); StereoOnWithCDCommand stereoOnWithCD = new StereoOnWithCDCommand(stereo); StereoOffCommand stereoOff = new StereoOffCommand(stereo); remote.SetCommand(0, livingRoomLightOn, livingRoomLightOff); remote.SetCommand(1, kitchenLightOn, kitchenLightOff); remote.SetCommand(2, ceilingFanOn, ceilingFanOff); remote.SetCommand(3, stereoOnWithCD, stereoOff); Assert.AreEqual("Living Room light is on", remote.OnButtonWasPushed(0)); Assert.AreEqual("Living Room light is off", remote.OffButtonWasPushed(0)); Assert.AreEqual("Kitchen light is on", remote.OnButtonWasPushed(1)); Assert.AreEqual("Kitchen light is off", remote.OffButtonWasPushed(1)); Assert.AreEqual("Living Room ceiling fan is on high", remote.OnButtonWasPushed(2)); Assert.AreEqual("Living Room ceiling fan is off", remote.OffButtonWasPushed(2)); Assert.AreEqual("Living Room stereo is on\n" + "Living Room stereo is set for CD input\n" + "Living Room Stereo volume set to 11", remote.OnButtonWasPushed(3)); Assert.AreEqual("Living Room stereo is off", remote.OffButtonWasPushed(3)); // Console.WriteLine(remote.toString()); }
public static void Test() { RemoteControl remoteControl = new RemoteControl(); Light livingRoomLight = new Light("Living Room"); Light kitchenLight = new Light("Kitchen"); CeilingFan ceilingFan = new CeilingFan("Living Room"); GarageDoor garageDoor = new GarageDoor("Garage"); Stereo stereo = new Stereo("Living Room"); TV tv = new TV("Living Room"); Hottub hottub = new Hottub(); LightOnCommand livingRoomLightOn = new LightOnCommand(livingRoomLight); LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight); LightOnCommand kitchenLightOn = new LightOnCommand(kitchenLight); LightOffCommand kitchenLightOff = new LightOffCommand(kitchenLight); CeilingFanOnCommand ceilingFanOn = new CeilingFanOnCommand(ceilingFan); CeilingFanOffCommand ceilingFanOff = new CeilingFanOffCommand(ceilingFan); GarageDoorUpCommand garageDoorUp = new GarageDoorUpCommand(garageDoor); GarageDoorDownCommand garageDoorDown = new GarageDoorDownCommand(garageDoor); StereoOnWithCDCommand stereoOnWithCD = new StereoOnWithCDCommand(stereo); StereoOffCommand stereoOff = new StereoOffCommand(stereo); TVOnCommand tvOn = new TVOnCommand(tv); TVOffCommand tvOff = new TVOffCommand(tv); HottubOnCommand hottubOn = new HottubOnCommand(hottub); HottubOffCommand hottubOff = new HottubOffCommand(hottub); Command[] partyOn = { livingRoomLightOn, stereoOnWithCD, tvOn, hottubOn }; Command[] partyOff = { livingRoomLightOff, stereoOff, tvOff, hottubOff }; MacroCommand partyOnCommand = new MacroCommand(partyOn); MacroCommand partyOffCommand = new MacroCommand(partyOff); remoteControl.setCommand(0, livingRoomLightOn, livingRoomLightOff); remoteControl.setCommand(1, kitchenLightOn, kitchenLightOff); remoteControl.setCommand(2, ceilingFanOn, ceilingFanOff); remoteControl.setCommand(3, stereoOnWithCD, stereoOff); remoteControl.setCommand(4, partyOnCommand, partyOffCommand); Console.WriteLine(remoteControl); remoteControl.onButtonWasPushed(0); remoteControl.offButtonWasPushed(0); remoteControl.onButtonWasPushed(1); remoteControl.offButtonWasPushed(1); remoteControl.onButtonWasPushed(2); remoteControl.offButtonWasPushed(2); remoteControl.onButtonWasPushed(3); remoteControl.offButtonWasPushed(3); Console.WriteLine("-------------------------------------------------------------- Party Mode On -----------------------------------------------"); remoteControl.onButtonWasPushed(4); remoteControl.offButtonWasPushed(4); remoteControl.undoButtonPushed(); }
static void Main(string[] args) { #region Strategy Pattern //Duck mallardDuck = new MallardDuck(); //mallardDuck.PerformQuack(); //mallardDuck.PerformFly(); //Duck modelDuck = new ModeldDuck(); //modelDuck.PerformFly(); //modelDuck.PerformQuack(); //modelDuck.setFlyBhavior(new FlyRocketPowered());// to change behavior at runtime just call setter method //modelDuck.PerformFly(); //mallardDuck.Display(); #endregion #region Observer Pattern //WeatherData weatherData = new WeatherData(); //CurrentConditionsDisplay currentConditions = new CurrentConditionsDisplay(weatherData); //weatherData.SetMeaserments(32.46f, 65, 30.4f); #endregion #region Decorator Pattern //Beverage beverage = new Espresso(); //Console.WriteLine(beverage.GetDiscription() + " TK-" + beverage.cost()); //Console.ReadLine(); #endregion #region Factory Pattern //PizzaStore nyPizzaStore = new NYPizzaStore(); //ProductPizza pizza = nyPizzaStore.Orderpizza("Cheese"); #endregion #region Command Pattern RemoteControl remoteControl = new RemoteControl();// invoker, it will be passed a command object that can be used to make request #region #region Create all devices in their Proper Location Light livingRoomLight = new Light("Living Room");// receiver of the request Light kitchenRoomLight = new Light("kitchen Room"); CeilingFan ceilingFan = new CeilingFan("Living Room"); Stereo stereo = new Stereo("Living Room"); GarageDoor garageDoor = new GarageDoor(); #endregion #region Create all the command object LightOnCommand livingRoomLightOn = new LightOnCommand(livingRoomLight); // create a command & pass it to the receiver LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight); // create a command & pass it to the receiver LightOnCommand KichenRoomLightOn = new LightOnCommand(kitchenRoomLight); // create a command & pass it to the receiver LightOffCommand KichenRoomLightOff = new LightOffCommand(kitchenRoomLight); // create a command & pass it to the receiver CeilingFanOnCommand ceilingFanOn = new CeilingFanOnCommand(ceilingFan); CeilingFanOffCommand ceilingFanOff = new CeilingFanOffCommand(ceilingFan); StereoOffCommand stereoOff = new StereoOffCommand(stereo); StereoOnWithCDCommand stereoOnWithCD = new StereoOnWithCDCommand(stereo); GarageDoorOpenCommand garageDoorOpen = new GarageDoorOpenCommand(garageDoor); GarageDoorDownCommand garageDoorDown = new GarageDoorDownCommand(garageDoor); #endregion #region load all commands in the remote slot //remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff); //remoteControl.SetCommand(1, KichenRoomLightOn, KichenRoomLightOff); //remoteControl.SetCommand(2, ceilingFanOn, ceilingFanOff); //remoteControl.SetCommand(3, stereoOnWithCD, stereoOff); #endregion #region action //Console.WriteLine(remoteControl); //remoteControl.OnButtonWasPushed(0); //remoteControl.OffButtonWasPushed(0); //remoteControl.OnButtonWasPushed(1); //remoteControl.OffButtonWasPushed(1); //remoteControl.OnButtonWasPushed(2); //remoteControl.OffButtonWasPushed(2); //remoteControl.OnButtonWasPushed(3); //remoteControl.OffButtonWasPushed(3); #endregion #endregion #region Undo Action in ceiling //CeilingFanHighCommand ceilingFanHigh = new CeilingFanHighCommand(ceilingFan); //CeilingFanMediumCommand ceilingFanMedium = new CeilingFanMediumCommand(ceilingFan); //CeilingFanLowCommand ceilingFanLow = new CeilingFanLowCommand(ceilingFan); //CeilingFanOffCommand ceilingFanOff = new CeilingFanOffCommand(ceilingFan); //remoteControl.SetCommand(0, ceilingFanMedium, ceilingFanOff); //remoteControl.SetCommand(1, ceilingFanHigh, ceilingFanOff); //remoteControl.OnButtonWasPushed(0); //remoteControl.OffButtonWasPushed(0); //Console.WriteLine(remoteControl); //remoteControl.undoButtonWasPushed(); //remoteControl.OnButtonWasPushed(1); //Console.WriteLine(remoteControl); //remoteControl.undoButtonWasPushed(); //Console.WriteLine(remoteControl); #endregion #region Macro Command ICommand[] partyOn = { livingRoomLightOn, stereoOnWithCD, ceilingFanOn, garageDoorOpen }; ICommand[] partyOff = { livingRoomLightOff, stereoOff, ceilingFanOff, garageDoorDown }; MacroCommand partyOnMacro = new MacroCommand(partyOn); MacroCommand partyOffMacro = new MacroCommand(partyOff); remoteControl.SetCommand(0, partyOnMacro, partyOffMacro); //Console.WriteLine(remoteControl); //Console.WriteLine("----Pushing Macro On----"); //remoteControl.OnButtonWasPushed(0); //Console.WriteLine("----Pushing Macro Off----"); //remoteControl.OffButtonWasPushed(0); //Console.WriteLine("----Pushing Macro Undo----"); //remoteControl.undoButtonWasPushed(); #endregion #endregion #region Adapter Pattern //MallaDuck duck = new MallaDuck(); //WildTurkey wildTurkey = new WildTurkey(); //IDuck turkeyAdapter = new TurkeyAdapter(wildTurkey); //Console.WriteLine("The Turkey Says..."); //wildTurkey.Gobble(); //wildTurkey.Fly(); //Console.WriteLine("\n The Duck Says..."); //testDuck(duck); //Console.WriteLine("\n The TurkeyAdapter Says..."); //testDuck(turkeyAdapter); #endregion #region Facade Pattern //Amplifier amp = new Amplifier(); //var tuner = new Tuner(); //DvdPlayer dvdPlayer = new DvdPlayer(); //CdPlayer cdPlayer = new CdPlayer(); //Projector projector = new Projector(); //TheaterLights theaterLights = new TheaterLights(); //Screen screen = new Screen(); //PopcornPopper popper = new PopcornPopper(); //TheaterLights light = new TheaterLights(); //HomeTheaterFacade theaterFacade = new HomeTheaterFacade( tuner, amp, dvdPlayer, cdPlayer, projector, light, screen, popper); //theaterFacade.WatchMovies("BatMan"); //Console.WriteLine("-------------------------"); //theaterFacade.EndMovie(); #endregion #region Template Method Pattern Tea tea = new Tea(); tea.PrepareRecipe(); #endregion #region #endregion #region #endregion #region #endregion #region #endregion Console.ReadLine(); }
static void Main(string[] args) { Console.WriteLine("SIMPLE REMOTE CONTROL"); var simpleRemoteControl = new SimpleRemoteControl(); var light = new Light("Living room"); var lightOn = new LightOnCommand(light); simpleRemoteControl.SetCommand(lightOn); simpleRemoteControl.ButtonWasPressed(); var garageDoorSimpleControl = new GarageDoor(); var garageOpen = new GarageDoorOpenCommand(garageDoorSimpleControl); simpleRemoteControl.SetCommand(garageOpen); simpleRemoteControl.ButtonWasPressed(); Console.WriteLine("REMOTE CONTROL"); var remoteControl = new RemoteControl(); var livingRoomLight = new Light("Living room"); var kitchenLight = new Light("Kitchen"); var ceilingFan = new CeilingFan("Living room"); var garageDoor = new GarageDoor(); var stereo = new Stereo("Living room"); var livingRoomLightOn = new LightOnCommand(livingRoomLight); var livingRoomLightOff = new LightOffCommand(livingRoomLight); var kitchenLightOn = new LightOnCommand(kitchenLight); var kitchenLightOff = new LightOffCommand(kitchenLight); var ceilingFanOn = new CeilingFanOnCommand(ceilingFan); var ceilingFanOff = new CeilingFanOffCommand(ceilingFan); var garageDoorOpen = new GarageDoorOpenCommand(garageDoor); var garageDoorClose = new GarageDoorCloseCommand(garageDoor); var stereoOnWithCd = new StereoOnWithCdCommand(stereo); var stereoOffWithCd = new StereoOffWithCdCommand(stereo); remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff); remoteControl.SetCommand(1, kitchenLightOn, kitchenLightOff); remoteControl.SetCommand(2, ceilingFanOn, ceilingFanOff); remoteControl.SetCommand(3, stereoOnWithCd, stereoOffWithCd); Console.WriteLine(remoteControl.ToString()); Console.WriteLine("-----------------FUNÇÕES EXECUTANDO"); remoteControl.OnButtonWasPushed(0); remoteControl.OffButtonWasPushed(0); remoteControl.OnButtonWasPushed(1); remoteControl.OffButtonWasPushed(1); remoteControl.OnButtonWasPushed(2); remoteControl.OffButtonWasPushed(2); remoteControl.OnButtonWasPushed(3); remoteControl.OffButtonWasPushed(3); Console.WriteLine(""); Console.WriteLine("REMOTE CONTROL WITH UNDO"); remoteControl.OnButtonWasPushed(0); remoteControl.OffButtonWasPushed(0); remoteControl.UndoButtonWasPushed(); remoteControl.OnButtonWasPushed(1); remoteControl.OffButtonWasPushed(1); remoteControl.UndoButtonWasPushed(); remoteControl.OnButtonWasPushed(2); remoteControl.OffButtonWasPushed(2); remoteControl.UndoButtonWasPushed(); remoteControl.OnButtonWasPushed(3); remoteControl.OffButtonWasPushed(3); remoteControl.UndoButtonWasPushed(); Console.WriteLine(""); Console.WriteLine("REMOTE CONTROL WITH UNDO OF THE CEILING FAN"); var remoteControlCeilingFan = new RemoteControl(); var ceilingFanHigh = new CeilingFanHightCommand(ceilingFan); var ceilingFanMedium = new CeilingFanMediumCommand(ceilingFan); remoteControlCeilingFan.SetCommand(0, ceilingFanMedium, ceilingFanOff); remoteControlCeilingFan.SetCommand(1, ceilingFanHigh, ceilingFanOff); remoteControlCeilingFan.OnButtonWasPushed(0); remoteControlCeilingFan.OffButtonWasPushed(0); Console.WriteLine(remoteControlCeilingFan.ToString()); remoteControlCeilingFan.UndoButtonWasPushed(); //remoteControlCeilingFan.OnButtonWasPushed(0); remoteControlCeilingFan.OnButtonWasPushed(1); Console.WriteLine(remoteControlCeilingFan.ToString()); remoteControlCeilingFan.UndoButtonWasPushed(); Console.WriteLine(""); Console.WriteLine("MACRO COMAND (PARTY MODE)"); var tv = new Tv("Living room"); var hottub = new Hottub(); var tvOn = new TvOnCommand(tv); var tvOff = new TvOffCommand(tv); var hottubOn = new HottubOnCommand(hottub); var hottubOff = new HottubOffCommand(hottub); var commandsPartyOn = new List <ICommand>() { livingRoomLightOn, stereoOnWithCd, tvOn, hottubOn }; var commandsPartyOff = new List <ICommand>() { livingRoomLightOff, stereoOffWithCd, tvOff, hottubOff }; var partyOn = new MacroCommand(commandsPartyOn); var partyOff = new MacroCommand(commandsPartyOff); var remoteControlParty = new RemoteControl(); remoteControlParty.SetCommand(0, partyOn, partyOff); Console.WriteLine(remoteControlParty.ToString()); Console.WriteLine("PUSHING MACRO ON"); remoteControlParty.OnButtonWasPushed(0); Console.WriteLine("PUSHING MACRO OFF"); remoteControlParty.OffButtonWasPushed(0); Console.ReadKey(); }