Beispiel #1
0
        private static void DriveVehicle(IVehicle vehicle, Driver driver)
        {
            ICommand powerOnCommand  = new PowerOnCommand(vehicle);
            ICommand powerOffCommand = new PowerOffCommand(vehicle);
            ICommand driveCommand    = new DriveCommand(vehicle);
            ICommand stopCommand     = new StopCommand(vehicle);

            driver.ExecuteCommand(powerOnCommand);
            driver.ExecuteCommand(driveCommand);
            driver.ExecuteCommand(stopCommand);
            driver.ExecuteCommand(powerOffCommand);
        }
Beispiel #2
0
        private static void Main(string[] args)
        {
            var         taxiFunction = new TaxiFunction();
            TaxiCommand driveCommand = new DriveCommand(taxiFunction);
            TaxiCommand senCommand   = new SendCommand();
            TaxiCommand exitCommand  = new ExitCommand();

            var invoker = new TaxiInvoker();

            invoker.SetCommand(senCommand);
            invoker.ExecuteCommand();

            invoker.SetCommand(driveCommand);
            invoker.ExecuteCommand();

            invoker.SetCommand(exitCommand);
            invoker.ExecuteCommand();


            Console.ReadKey();
        }