static void Main(string[] args)
        {
            RemoteControl remoteControl = new RemoteControl();
            //GarageDoor
            GarageDoor             garageDoor             = new GarageDoor();
            GarageDoorCloseCommand garageDoorCloseCommand = new GarageDoorCloseCommand(garageDoor);
            GarageDoorOpenCommand  garageDoorOpenCommand  = new GarageDoorOpenCommand(garageDoor);
            Light           light           = new Light();
            LightOnCommand  lightOnCommand  = new LightOnCommand(light);
            LightOffCommand lightOffCommand = new LightOffCommand(light);



            remoteControl.SetCommand(0, garageDoorOpenCommand, garageDoorCloseCommand);
            remoteControl.SetCommand(1, lightOnCommand, lightOffCommand);



            remoteControl.OnButtonWasPushed(0);
            remoteControl.OnButtonWasPushed(1);

            Console.WriteLine(remoteControl);

            remoteControl.OffButtonWasPushed(0);
            Console.ReadKey();
        }
Exemple #2
0
        public static void Structural_Bridge()
        {
            var remoteControl = new RemoteControl(new SonyTV());

            remoteControl.TurnOn();

            // we want to use an advanced remote control
            var advRemoteControl = new AdvancedRemoteControl(new SonyTV());

            advRemoteControl.TurnOn();

            // If we want a new brand, just add a new class that implements the IDevice interface
            var remoteControlSamsung = new RemoteControl(new SamsungTV());

            remoteControlSamsung.TurnOn();

            // This is the Bridge pattern, We don't have to create several new classes and add them to our hierachy
            // We use the Bridge pattern when we have a hierarchy that can grow in two different dimensions
            // We can split a complex hierarchy into two separate hierarchies that can grow independently
            // this makes our application design more extensible and maintainable.
        }
Exemple #3
0
        static void Main(string[] args)
        {
            var    remote = new RemoteControl();
            string userInput;

            remote.SetCommandForButton("add", new Add());                 //назначение команд
            remote.SetCommandForButton("print", new Print());
            remote.SetCommandForButton("printlog", new PrintLog());
            remote.SetCommandForButton("undo", new UnDo());


            do
            {
                Console.Clear();
                Console.WriteLine("Выберите вариант ниже:");
                Console.WriteLine(remote);                //команды в интерфейсе
                Console.Write("\nВаш выбор: ");
                userInput = Console.ReadLine().ToLower(); //ввод не зависит от CAPSа
                remote.PushButton(userInput);
                Console.ReadKey();
            } while (userInput != "exit");
        }
        static void Main(string[] args)
        {
            RemoteControl remoteControl = new RemoteControl();
            //GarageDoor
            GarageDoor             garageDoor             = new GarageDoor();
            GarageDoorCloseCommand garageDoorCloseCommand = new GarageDoorCloseCommand(garageDoor);
            GarageDoorOpenCommand  garageDoorOpenCommand  = new GarageDoorOpenCommand(garageDoor);

            Light           light           = new Light();
            LightOnCommand  lightOnCommand  = new LightOnCommand(light);
            LightOffCommand lightOffCommand = new LightOffCommand(light);

            TV           tv           = new TV();
            TvOnCommand  tvOnCommand  = new TvOnCommand(tv);
            TvOffCommand tvOffCommand = new TvOffCommand(tv);

            Stereo           stereo           = new Stereo();
            StereoOnCommand  stereoOnCommand  = new StereoOnCommand(stereo);
            StereoOffCommand stereoOffCommand = new StereoOffCommand(stereo);


            remoteControl.SetCommand(0, garageDoorOpenCommand, garageDoorCloseCommand);
            remoteControl.SetCommand(1, lightOnCommand, lightOffCommand);
            remoteControl.SetCommand(2, tvOnCommand, tvOffCommand);
            remoteControl.SetCommand(3, stereoOnCommand, stereoOffCommand);


            remoteControl.OnButtonWasPushed(0);
            remoteControl.OnButtonWasPushed(1);
            remoteControl.OnButtonWasPushed(2);
            remoteControl.OnButtonWasPushed(3);

            Console.WriteLine(remoteControl);

            remoteControl.OffButtonWasPushed(0);
            Console.ReadKey();
        }