コード例 #1
0
        static void Main(string[] args)
        {
            //下订单:2巧克力 1牛奶 的 longblack

            //1 longblack
            Drink order = new LongBlack();

            Console.WriteLine("费用:\t" + order.Cost());
            Console.WriteLine("描述:\t" + order.GetDescription());

            //2 加牛奶
            order = new Milk(order);
            Console.WriteLine("费用:\t" + order.Cost());
            Console.WriteLine("描述:\t" + (order as Decorator).GetDescription());

            //3 加巧克力
            order = new Chocolate(order);
            Console.WriteLine("费用:\t" + order.Cost());
            Console.WriteLine("描述:\t" + (order as Decorator).GetDescription());

            //3 加巧克力
            order = new Chocolate(order);
            Console.WriteLine("费用:\t" + order.Cost());
            Console.WriteLine("描述:\t" + (order as Decorator).GetDescription());

            Console.ReadLine();
        }
コード例 #2
0
 static void Main(string[] args)
 {
     var caffeLatte = new Milk(new HouseBlend());
     DescribeBeverage(caffeLatte);
     var espressoMocha = new Mocha(new Espresso());
     DescribeBeverage(espressoMocha);
     Console.ReadKey();
 }
コード例 #3
0
        public static void Main(string[] args)
        {
            var coffee = new Coffee();
            var milk   = new Milk(coffee);
            var sugar  = new Sugar(milk);

            Console.WriteLine(sugar.Name + ", price: " + sugar.Price);
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: DayLater/Patterns
        static void Main(string[] args)
        {
            var teaWithSugarAndMilk = new Milk(new Sugar(new Tea()));
            var coffeeWithChocolate = new Chocolate(new Coffee());

            Console.WriteLine(coffeeWithChocolate);
            Console.WriteLine(teaWithSugarAndMilk);
        }
コード例 #5
0
        static void Main(string[] args)
        {
            Baverage baverage = new DarkRoast("Какое-то кофе!");

            baverage = new Milk(baverage, "Молоко!");
            baverage = new Milk(baverage, "Молоко!");
            baverage = new Soy(baverage, "Soy!");
            Console.WriteLine(baverage.getDescription() + "=" + baverage.cost() + "$");
        }
コード例 #6
0
        /// <summary>
        /// Здесь мы используем паттерн Декоратор
        /// </summary>
        private static void Main()
        {
            Beverage beverage = new Expresso();

            beverage = new Mocha(beverage);
            beverage = new Mocha(beverage);
            beverage = new Milk(beverage);
            Console.WriteLine($"Напиток обошелся в {beverage.Cost()} рублей, в напитке {beverage.GetDescription()}");
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: ElenaSerbova/Patterns
        static void Main(string[] args)
        {
            Beverage beverage = new Espresso();

            beverage = new Milk(beverage);
            beverage = new Chocolate(beverage);

            Console.WriteLine(beverage.Description());
            Console.WriteLine(beverage.Cost());
        }
コード例 #8
0
        static void Main(string[] args)
        {
            Expresso cafeExpresso                   = new Expresso();
            Caramel  cafeExpressoWithCaramel        = new Caramel(cafeExpresso);
            Milk     cafeExpressoWithCaramelAndMilk = new Milk(cafeExpressoWithCaramel);

            Console.WriteLine("Expresso: " + cafeExpresso.Cost());
            Console.WriteLine("Expresso Caramel: " + cafeExpressoWithCaramel.Cost());
            Console.WriteLine("Expresso Caramel And Milk: " + cafeExpressoWithCaramelAndMilk.Cost());
            Console.ReadKey();
        }
コード例 #9
0
        static void Main(string[] args)
        {
            Beverage coffee = new Espresso();

            coffee = new Milk(coffee);
            coffee = new Mocha(coffee);
            coffee = new Whip(coffee);

            Console.WriteLine($"The beverage is {coffee.Description} it's cost is : {coffee.Cost()}$");
            Console.ReadKey();
        }
コード例 #10
0
        static void Main(string[] args)
        {
            Beverage beverage = new DarkRoast();

            Console.WriteLine("Drink name: {0}, cost: {1}eu", beverage.GetDescription(), beverage.Cost());

            Beverage beverage2 = new Expresso();

            beverage2 = new Milk(beverage2);
            beverage2 = new Whip(beverage2);
            Console.WriteLine("Drink name: {0}, cost: {1}eu", beverage2.GetDescription(), beverage2.Cost());
        }
コード例 #11
0
        static void Main(string[] args)
        {
            var espresso = new Espresso();

            Console.WriteLine(espresso.GetDescription() + " - $" + espresso.GetCost());

            var espressoWithMilk = new Milk(new Espresso());

            Console.WriteLine(espressoWithMilk.GetDescription() + " - $" + espressoWithMilk.GetCost());

            Console.ReadKey();
        }
コード例 #12
0
        static void Main(string[] args)
        {
            Console.WriteLine("<Decorating an Expresso>");
            Beverage expresso = new Expresso();

            Console.WriteLine($"What: {expresso.getDescription(),-40} How Much: ${expresso.cost():F2}");
            expresso = new Cocoa(expresso);
            Console.WriteLine($"What: {expresso.getDescription(),-40} How Much: ${expresso.cost():F2}");
            expresso = new Milk(expresso);
            Console.WriteLine($"What: {expresso.getDescription(),-40} How Much: ${expresso.cost():F2}");
            Console.WriteLine("<Tasty!>");
        }
コード例 #13
0
        static void Main(string[] args)
        {
            Beverage beverage = new HouseBlend();

            beverage = new Milk(beverage);
            beverage = new Whip(beverage);
            beverage = new Whip(beverage);
            beverage = new Whip(beverage);
            beverage = new Whip(beverage);
            beverage = new Mocha(beverage);
            beverage = new Soy(beverage);
            Console.WriteLine($"{beverage.GetDescription()} {beverage.Cost()}");
        }
コード例 #14
0
        static void Main(string[] args)
        {
            Title.UpperIndent(Assembly.GetExecutingAssembly());

            Beverage beverage1 = new Coffee("Simple coffee", 20, Size.Small);
            Beverage beverage2 = new Milk("Milk", 4, beverage1);
            Beverage beverage3 = new Milk("Milk", 4, beverage2);

            Console.WriteLine(beverage3.GetCost());
            Console.WriteLine(beverage3.GetDescription());

            Title.BottonIndent();
        }
コード例 #15
0
        static void Main(string[] args)
        {
            ICoffee coffee = new Coffee();

            coffee = new Sugar(coffee);
            coffee = new Sugar(coffee);
            coffee = new Sugar(coffee);
            coffee = new Whipp(coffee);
            coffee = new Milk(coffee);

            Console.WriteLine("Details: " + coffee.GetDetails());
            Console.WriteLine("Cost: " + coffee.GetCost());

            Console.ReadKey();
        }
コード例 #16
0
        static void Main(string[] args)
        {
            Beverage beverage1 = new HouseBlend();

            beverage1      = new Milk(beverage1);
            beverage1      = new Soy(beverage1);
            beverage1      = new Soy(beverage1);
            beverage1.Size = CupSize.Small;
            Console.WriteLine(string.Format("{0}: $ {1}", beverage1.GetDescription(), beverage1.Cost()));
            beverage1.Size = CupSize.Medium;
            Console.WriteLine(string.Format("{0}: $ {1}", beverage1.GetDescription(), beverage1.Cost()));
            beverage1.Size = CupSize.Large;
            Console.WriteLine(string.Format("{0}: $ {1}", beverage1.GetDescription(), beverage1.Cost()));
            beverage1 = new PrettyDescriptionDecorator(beverage1);
            Console.WriteLine(string.Format("{0}: $ {1}", beverage1.GetDescription(), beverage1.Cost()));
            Console.ReadKey();
        }
コード例 #17
0
ファイル: Program.cs プロジェクト: Xander73/Patterns
        static void Main(string[] args)
        {
            Beverage beverage = new Coffee();

            beverage = new Milk(beverage);
            beverage = new Sugar(beverage);
            beverage = new Sugar(beverage);

            Console.WriteLine("Description - " + beverage.Description);
            Console.WriteLine("Cost - " + beverage.Cost());
            Console.WriteLine();

            beverage = new Sugar(new Sugar(new Tea()));

            Console.WriteLine("Description - " + beverage.Description);
            Console.WriteLine("Cost - " + beverage.Cost());

            Console.Read();
        }
コード例 #18
0
ファイル: Program.cs プロジェクト: Meldow/DesignPatterns
        static void Main(string[] args)
        {
            Beverage beverage = new HouseBlend();

            Console.WriteLine(beverage.ToString());

            // dark roast with double mocha and whip
            Beverage beverage2 = new DarkRoast();

            beverage2 = new Mocha(beverage2);
            beverage2 = new Mocha(beverage2);
            beverage2 = new Milk(beverage2);
            Console.WriteLine(beverage2.ToString());

            // espresso with milk
            Beverage beverage3 = new Espresso();

            beverage3 = new Milk(beverage3);
            Console.WriteLine(beverage3.ToString());
        }
コード例 #19
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            //单品黑咖啡
            Coffee coffee = new LongBlack();

            MyPrint(coffee);

            //黑咖啡的基础上+牛奶
            coffee = new Milk(coffee);//生成装饰对象(牛奶)的同时将之前被装饰者(黑咖啡)注进去,达到累加效果
            MyPrint(coffee);

            //依此类推
            //可以继续添加装饰者
            coffee = new Chocolate(coffee);
            MyPrint(coffee);

            Console.ReadLine();
        }
コード例 #20
0
        static void Main(string[] args)
        {
            Beverage beverage1 = new Espresso();

            Console.WriteLine("{0} costs {1}$", beverage1.GetDescription(), beverage1.cost());

            Beverage beverage2 = new DarkRoast();

            beverage2 = new Milk(beverage2);
            beverage2 = new Mocha(beverage2);
            beverage2 = new Whip(beverage2);
            beverage2.GetDescription();
            Console.WriteLine("{0} costs {1}$", beverage2.GetDescription(), beverage2.cost());

            Beverage beverage3 = new Decaf();

            beverage3.setSize(Beverage.Size.Venti);
            beverage3 = new Soy(beverage3);
            beverage3 = new Whip(beverage3);
            Console.WriteLine("{0} costs {1}$", beverage3.GetDescription(), beverage3.cost());

            Console.ReadLine();
        }
コード例 #21
0
        public static void Main()
        {
            var coffee = new Coffee("Filtered");

            coffee.Prepare();


            Console.WriteLine("Making coffee with Milk and Chocolate");
            var customizableDrink = new CustomizableDrink(coffee);

            Milk      milk      = new Milk();
            Chocolate chocolate = new Chocolate();

            customizableDrink.AddExtraIngredient(milk);
            customizableDrink.AddExtraIngredient(chocolate);
            customizableDrink.Prepare();


            Console.WriteLine("Making coffee with Milk");
            var customizableDrink = new CustomizableDrink(coffee);

            customizableDrink.AddExtraIngredient(milk);
            customizableDrink.Prepare();
        }