Exemple #1
0
 public static void Main(string[] args)
 {
     // our application will need some reveiver object
     Television device = new Television();
     // our application will need an invoker object, which
     // in turns relies on concrete command objects:
     ICommand on   = new OnCommand(device);  // command to switch device on
     ICommand off  = new OffCommand(device); // command to switch device off
     ICommand up   = new UpCommand(device);  // command to turn volume up
     ICommand down = new DownCommand(device);// command to turn volume down
     // now we are ready to create our invoker object which
     // we should think of as some sort of application menu.
     RemoteControl menu = new RemoteControl(on, off, up, down);
     // client code is now able to access the invoker object
     menu.SwitchPowerOn();
     menu.RaiseVolume();
     menu.RaiseVolume();
     menu.RaiseVolume();
     menu.LowerVolume();
     menu.SwitchPowerOff();
 }