Esempio n. 1
0
        /// <summary>
        /// Definition:
        /// The decorator pattern, ataches additional responsibility to an object dynamically. Decorators provides a flexible
        /// alternative to subclassing for extending functionality.
        /// </summary>
        static void Main(string[] args)
        {
            Beverage espressoWithCaramelAndSoy = new Caramel(new Soy(new Espresso()));
            Beverage espressoWithCaramel       = new Caramel(new Espresso());
            Beverage decafWithSoyAndCaramel    = new Soy(new Caramel(new Decaf()));

            Console.WriteLine($"Espresso with caramel and soy {espressoWithCaramelAndSoy.Cost()}$");
            Console.WriteLine($"Espresso with caramel {espressoWithCaramel.Cost()}$");
            Console.WriteLine($"Decaf with soy and caramel {decafWithSoyAndCaramel.Cost()}$");

            Console.ReadKey();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            //Order a Latte with Cream
            Coffee latteWithCream = new Latte();
            latteWithCream = new WhipCream(latteWithCream);
            Console.WriteLine(latteWithCream.GetDescription() + " at $" + latteWithCream.GetCost());

            //Order an Expresso with Caramel and Cream
            Coffee expressoWithCaramelAndCream = new Expresso();
            expressoWithCaramelAndCream = new WhipCream(expressoWithCaramelAndCream);
            expressoWithCaramelAndCream = new Caramel(expressoWithCaramelAndCream);
            Console.WriteLine(expressoWithCaramelAndCream.GetDescription() + " at $" + expressoWithCaramelAndCream.GetCost());
        }
        static void Main(string[] args)
        {
            //Order a Latte with Cream
            Coffee latteWithCream = new Latte();

            latteWithCream = new WhipCream(latteWithCream);
            Console.WriteLine(latteWithCream.GetDescription() + " at $" + latteWithCream.GetCost());

            //Order an Expresso with Caramel and Cream
            Coffee expressoWithCaramelAndCream = new Expresso();

            expressoWithCaramelAndCream = new WhipCream(expressoWithCaramelAndCream);
            expressoWithCaramelAndCream = new Caramel(expressoWithCaramelAndCream);
            Console.WriteLine(expressoWithCaramelAndCream.GetDescription() + " at $" + expressoWithCaramelAndCream.GetCost());
        }
        public static void Main(string[] args)
        {
            var coffee = new Cream(new Caramel(new Cappichino()));

            System.Console.WriteLine(coffee.GetDescription());
            System.Console.WriteLine(coffee.Cost());

            var coffee1 = new Cream(new Cappichino());

            System.Console.WriteLine(coffee1.GetDescription());
            System.Console.WriteLine(coffee1.Cost());

            var coffee2 = new Cappichino();

            System.Console.WriteLine(coffee2.GetDescription());
            System.Console.WriteLine(coffee2.Cost());

            var coffee3 = new Caramel(new Cappichino());

            System.Console.WriteLine(coffee3.GetDescription());
            System.Console.WriteLine(coffee3.Cost());
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            var client = new Client();

            var expresso = new Expresso();

            //Only Expresso
            client.ClientCode(expresso);
            Console.WriteLine();
            //Expresso with caramel
            var test = new Caramel(expresso);

            //Expresso with caramel and chocolate
            var test2 = new Chocolate(new Caramel(expresso));

            client.ClientCode(test);
            Console.WriteLine();

            client.ClientCode(test2);
            Console.WriteLine();

            Console.ReadLine();
        }