/// <summary> /// The Command design pattern encapsulates a request as an object, /// thereby allowing us developers to treat that request differently based upon what class receives said command. /// Further, it enables much more complex architectures, /// and even enables operations such as undo/redo. /// </summary> /// <param name="args"></param> static void Main(string[] args) { // creating a new receiver Lemp lemp = new Lemp(); // creating a new command and passing it the receiver TurnOffCommand turnOffCommand = new TurnOffCommand(lemp); TurnOnCommand turnOnCommand = new TurnOnCommand(lemp); // creating a new invoker and passing it the commands RemoteInvoker remoteInvoker = new RemoteInvoker(turnOffCommand, turnOnCommand); // executing the command remoteInvoker.TurnOffCommand.Execute(); Console.ReadKey(); }
/// <summary> /// the constructor we are passing our commands using dependency injection /// </summary> /// <param name="turnOffCommand"></param> /// <param name="turnOnCommand"></param> public RemoteInvoker(TurnOffCommand turnOffCommand, TurnOnCommand turnOnCommand) { this._turnOffCommand = turnOffCommand; this._turnOnCommand = turnOnCommand; }