Exemplo n.º 1
0
        /*
         * The role of the decorator pattern is to add the state and behavior to an object dynamically.
         * The object does not know that it is being decorated therefore it is useful pattern for evolving systems.
         * You pass the object to an instance of another class that the other class extends it (decorates it).
         * So the original object being passed passes the open/closed principle, where it is extended but not modified.
         * This is why this pattern is so popular.
         * This example was taken from http://www.dotnetforall.com/c-decorator-pattern/ a more realistic example can
         * be found at https://assist-software.net/blog/implementation-decorator-pattern-c
         */

        public static void launchExample()
        {
            ICar traditionalCar = new Car();

            traditionalCar.Drive();
            traditionalCar.Brake();

            //Pass the car object into the decorator
            SuperCar superCar = new SuperCar(traditionalCar);

            superCar.Drive();
            superCar.Music();
            superCar.Brake();
            Console.Read();
        }