コード例 #1
0
        public RemoteControl()
        {
            onCommands = new Command[7];
            offCommands = new Command[7];
            Command noCommand = new NoCommand();

            for (int i = 0; i < 7; i++)
            {
                onCommands[i] = noCommand;
                offCommands[i] = noCommand;
            }
            undoCommand = noCommand;
        }
コード例 #2
0
 public void setCommand(Command command)
 {
     slot = command;
 }
コード例 #3
0
ファイル: Program.cs プロジェクト: krishkhan/DesignPatterns
        static void Main(string[] args)
        {
            Light light = new Light("Any");
            Light kitchenLight = new Light("Kitchen");
            Light livingRoomLight = new Light("Living room");
            Light bedroomLight = new Light("Bedroom");

            Command lightONBtn = new LightONCommand(light);
            Command lightOffBtn = new LightOFFCommand(light);

            Command kitchenLightON = new LightONCommand(kitchenLight);
            Command kitchenLightOFF = new LightOFFCommand(kitchenLight);

            Command livingRoomON = new LightONCommand(livingRoomLight);
            Command livingRoomOFF = new LightOFFCommand(livingRoomLight);

            SimpleRemoteControl simpRemoteCntrl = new SimpleRemoteControl();

            simpRemoteCntrl.SetCommand(0,lightONBtn,lightOffBtn);
            simpRemoteCntrl.SetCommand(1, kitchenLightON, kitchenLightOFF);
            simpRemoteCntrl.SetCommand(2, livingRoomON, livingRoomOFF);

            simpRemoteCntrl.OnButtonPushed(0);
            simpRemoteCntrl.OffButtonPushed(0);

            simpRemoteCntrl.OnButtonPushed(1);
            simpRemoteCntrl.OffButtonPushed(1);

            simpRemoteCntrl.OnButtonPushed(2);
            simpRemoteCntrl.OffButtonPushed(2);

            CeilingFan ceilingFanLivingRoom = new CeilingFan("Living Room");
            Command ceilingFanHighCommand = new CeilingFanHighCommand(ceilingFanLivingRoom);
            Command ceilingFanOffCommand = new CeilingFanOffCommand(ceilingFanLivingRoom);
            simpRemoteCntrl.SetCommand(3, ceilingFanHighCommand, ceilingFanOffCommand);

            simpRemoteCntrl.OnButtonPushed(3);

            Console.WriteLine("\n Start of macro \n");

            Command[] partyCommandsOn = new Command[] { lightONBtn,kitchenLightON,livingRoomON};
            Command[] partyCommandsOff = new Command[] {lightOffBtn,kitchenLightOFF,livingRoomOFF };

            MacroCommand macroCommandON = new MacroCommand(partyCommandsOn);
            MacroCommand macroCommandOff = new MacroCommand(partyCommandsOff);

            simpRemoteCntrl.SetCommand(0, macroCommandON, macroCommandOff);

            simpRemoteCntrl.OnButtonPushed();
            simpRemoteCntrl.OffButtonPushed();

            Console.WriteLine(simpRemoteCntrl.ToString());
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: krishkhan/DesignPatterns
 public void SetCommand(int slot,Command onCommand, Command offCommand)
 {
     onCommands[slot] = onCommand;
     offCommands[slot] = offCommand;
 }
コード例 #5
0
ファイル: Program.cs プロジェクト: krishkhan/DesignPatterns
 public void OnButtonPushed(int slot)
 {
     onCommands[slot].Execute();
     undoCommand = onCommands[slot];
 }
コード例 #6
0
ファイル: Program.cs プロジェクト: krishkhan/DesignPatterns
 public void OffButtonPushed(int slot)
 {
     offCommands[slot].Execute();
     undoCommand = offCommands[slot];
 }
コード例 #7
0
ファイル: Program.cs プロジェクト: krishkhan/DesignPatterns
 public MacroCommand(Command[] commands)
 {
     this.commands = commands;
 }
コード例 #8
0
 public void SetCommand(Command command)
 {
     this.command = command;
 }
コード例 #9
0
 public void onButtonWasPushed(int slot)
 {
     onCommands[slot].execute();
     undoCommand = onCommands[slot];
 }
コード例 #10
0
ファイル: Command.cs プロジェクト: usamanoman/Design-Patterns
 public MacroCommand(Command[] listOfCommands)
 {
     md = listOfCommands;
 }
コード例 #11
0
ファイル: Invoker.cs プロジェクト: r-abbott/DesignPatterns
 public void Record(string statement)
 {
     var command = new Command(_receiver, statement);
     command.Execute();
     StoreCommand(command);
 }