Beispiel #1
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.
        }