Exemple #1
0
        static void Main(string[] args)
        {
            Beverage beverage = new Espresso();

            Console.WriteLine("{0} ${1}", beverage.GetDescription(), beverage.Cost());
            beverage.SetSize(3);
            Console.WriteLine("{0} ${1}", beverage.GetDescription(), beverage.Cost());

            Beverage beverage2 = new Mocha(beverage);
            Console.WriteLine("{0} ${1}", beverage2.GetDescription(), beverage2.Cost());
            beverage2 = new Mocha(beverage2);
            Console.WriteLine("{0} ${1}", beverage2.GetDescription(), beverage2.Cost());

            beverage2.SetSize(2);
            Console.WriteLine("{0} ${1}", beverage2.GetDescription(), beverage2.Cost());
            Console.ReadKey();
        }
Exemple #2
0
        static void Main(string[] args)
        {
            Beverage beverage = new Espresso();

            Console.WriteLine($"{beverage.GetDescription()} ${beverage.Cost()}");

            Beverage beverage1 = new HouseBlend();

            beverage1 = new Soy(beverage1);
            beverage1 = new Mocha(beverage1);
            beverage1 = new Mocha(beverage1);
            Console.WriteLine($"{beverage1.GetDescription()} ${beverage1.Cost()}");

            Console.ReadLine();
        }
Exemple #3
0
        static void Main(string[] args)
        {
            Beverage beverage = new Espresso();

            Console.WriteLine($"{beverage.GetDescription()} : {beverage.Cost()}");

            //New beverage
            //Wrap it with a mocha, second mocha and then whip
            Beverage beverage2 = new Espresso();

            beverage2 = new Mocha(beverage2);
            beverage2 = new Mocha(beverage2);
            beverage2 = new Whip(beverage2);
            Console.WriteLine($"{beverage2.GetDescription()} : {beverage2.Cost()}");
        }
        static void Main(string[] args)
        {
            Bevarage bevarage = new Espresso();

            Console.WriteLine("{0} ${1}", bevarage.Description, bevarage.Cost().ToString());

            bevarage = new DarkRoast();

            bevarage = new Mocha(bevarage);



            Console.WriteLine("{0} ${1}", bevarage.Description, bevarage.Cost().ToString());

            Console.ReadLine();
        }
Exemple #5
0
        static void Main(string[] args)
        {
            Beverage beverage = new Espresso();

            Console.WriteLine(beverage.GetDescription() + " $" + beverage.Cost());

            Beverage beverage2 = new HouseBlend();

            beverage2 = new Mocha(beverage2);
            beverage2 = new Soy(beverage2);
            beverage2 = new Whip(beverage2);
            Console.WriteLine(beverage2.GetDescription() + " $" + beverage2.Cost());

            Beverage beverage3 = new DarkRoase();

            beverage3 = new Mocha(beverage3);
            beverage3 = new Mocha(beverage3);
            beverage3 = new Whip(beverage3);
            Console.WriteLine(beverage3.GetDescription() + " $" + beverage3.Cost());

            //Console.ReadLine();
            Console.WriteLine("---------------------\n");

            // 我买了个苹果手机
            Phone phone = new ApplePhone();
            // 现在想贴膜了
            Decorator applePhoneWithSticker = new Sticker(phone);

            // 扩展贴膜行为
            applePhoneWithSticker.Print();
            Console.WriteLine("----------------------\n");

            // 现在我想有挂件了
            Decorator applePhoneWithAccessories = new Accessories(phone);

            // 扩展手机挂件行为
            applePhoneWithAccessories.Print();
            Console.WriteLine("----------------------\n");

            // 现在我同时有贴膜和手机挂件了
            Sticker     sticker = new Sticker(phone);
            Accessories applePhoneWithAccessoriesAndSticker = new Accessories(sticker);

            applePhoneWithAccessoriesAndSticker.Print();

            Console.ReadLine();
        }
Exemple #6
0
        static void Main(string[] args)
        {
            Beverage.Beverage espresso = new Espresso();
            Console.WriteLine($"{espresso.GetDescription()}, ${espresso.Cost()}");

            Beverage.Beverage soyHouseBlend = new HouseBlend();
            soyHouseBlend = new Soy(soyHouseBlend);
            Console.WriteLine($"{soyHouseBlend.GetDescription()}, ${soyHouseBlend.Cost()}");

            Beverage.Beverage doubleMochaWithWhipInDarkRoast = new DarkRoast();
            doubleMochaWithWhipInDarkRoast = new Mocha(doubleMochaWithWhipInDarkRoast);
            doubleMochaWithWhipInDarkRoast = new Mocha(doubleMochaWithWhipInDarkRoast);
            doubleMochaWithWhipInDarkRoast = new Whip(doubleMochaWithWhipInDarkRoast);

            Console.WriteLine($"{doubleMochaWithWhipInDarkRoast.GetDescription()}, ${doubleMochaWithWhipInDarkRoast.Cost()}");
            Console.ReadKey();
        }
Exemple #7
0
        public static void Start()
        {
            IBeverage beverage = new Espresso(BeverageSize.TALL);

            Console.WriteLine($"{beverage.Description} ${beverage.Cost()}");

            IBeverage beverage2 = new Whip(new Mocha(new Mocha(new DarkRoast(BeverageSize.GRANDE))));

            Console.WriteLine($"{beverage2.Description} ${beverage2.Cost()}");

            IBeverage beverage4 = new HouseBlend(BeverageSize.VENTI);

            beverage4 = new Soy(beverage4);
            beverage4 = new Mocha(beverage4);
            beverage4 = new Whip(beverage4);

            Console.WriteLine($"{beverage4.Description} ${beverage4.Cost()}");
        }
Exemple #8
0
        static void Main(string[] args)
        {
            Beverage beverage = new Espresso();

            Console.WriteLine($"{beverage.GetDescription()} ${beverage.Cost()}");

            Beverage beverage2 = new DarkRoast();

            beverage2 = new Mocha(beverage2);
            beverage2 = new Mocha(beverage2);
            beverage2 = new Whip(beverage2);
            Console.WriteLine($"{beverage2.GetDescription()} ${beverage2.Cost()}");

            Beverage beverage3 = new HouseBlend();

            beverage3 = new Soy(beverage3);
            beverage3 = new Mocha(beverage3);
            beverage3 = new Whip(beverage3);
            Console.WriteLine($"{beverage3.GetDescription()} ${beverage3.Cost()}");
        }
Exemple #9
0
        public void DecoratorTest()
        {
            Beverage beverage = new Espresso();

            Console.WriteLine($"{beverage.GetDescription()} ${beverage.Cost()}");

            Beverage beverage2 = new DarkRoast();

            beverage2 = new Mocha(beverage2);
            beverage2 = new Mocha(beverage2);
            beverage2 = new Whip(beverage2);
            Console.WriteLine($"{beverage2.GetDescription()} ${beverage2.Cost()}");

            Beverage beverage3 = new HouseBlend();

            beverage3 = new Soy(beverage3);
            beverage3 = new Mocha(beverage3);
            beverage3 = new Whip(beverage3);
            Console.WriteLine($"{beverage3.GetDescription()} ${beverage3.Cost()}");
        }
        public void TestDecoratorPattern()
        {
            Beverage beverage = new Espresso();

            Assert.Equal("Espresso $1.99", beverage.Description + " $" + beverage.Cost());

            Beverage beverage2 = new DarkRoast();

            beverage2 = new Mocha(beverage2);
            beverage2 = new Mocha(beverage2);
            beverage2 = new Whip(beverage2);
            Assert.Equal("Dark Roast Coffee, Mocha, Mocha, Whip $1.49", beverage2.Description + " $" + beverage2.Cost());

            Beverage beverage3 = new HouseBlend();

            beverage3 = new Soy(beverage3);
            beverage3 = new Mocha(beverage3);
            beverage3 = new Whip(beverage3);
            Assert.Equal("House Blend Coffee, Soy, Mocha, Whip $1.34", beverage3.Description + " $" + beverage3.Cost());
        }
    static void Main()
    {
        Beverage beverage0 = new Espresso();

        System.Console.WriteLine($"{beverage0.GetDescription()} {beverage0.Cost()} $");

        Beverage beverage1 = new DarkRoast();

        beverage1 = new Mocha(beverage1);
        beverage1 = new Mocha(beverage1);
        beverage1 = new Whip(beverage1);
        System.Console.WriteLine($"{beverage1.GetDescription()} {beverage1.Cost()} $");

        Beverage beverage2 = new HouseBlend();

        beverage2 = new Soy(beverage2);
        beverage2 = new Mocha(beverage2);
        beverage2 = new Whip(beverage2);
        System.Console.WriteLine($"{beverage2.GetDescription()} {beverage2.Cost()} $");
    }
Exemple #12
0
        private static void TestDecoratorPattern()
        {
            IBeverage beverage = new Espresso(CoffeeSize.Tall);

            Console.WriteLine("{0} $ {1}", beverage.Description, beverage.Cost());

            IBeverage beverage1 = new DarkRoast(CoffeeSize.Tall);

            beverage1 = new Mocha(beverage1);
            beverage1 = new Mocha(beverage1);
            beverage1 = new Whip(beverage1);
            Console.WriteLine($"{beverage1.Description} $ {beverage1.Cost()}");

            IBeverage beverage2 = new HouseBlend(CoffeeSize.Tall);

            beverage2 = new Soy(beverage2);
            beverage2 = new Mocha(beverage2);
            beverage2 = new Whip(beverage2);
            Console.WriteLine($"{beverage2.Description} $ {beverage2.Cost()}");
        }
Exemple #13
0
        public void StarbuzzCoffeeTest()
        {
            var beverage = new Espresso();

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

            Beverage beverage2 = new DarkRoast();

            beverage2 = new Mocha(beverage2);
            beverage2 = new Mocha(beverage2);
            beverage2 = new Whip(beverage2);

            Console.WriteLine(beverage2.Description + " $ " + beverage2.Cost());

            Beverage beverage3 = new HouseBlend();

            beverage3 = new Soy(beverage3);
            beverage3 = new Mocha(beverage3);
            beverage3 = new Whip(beverage3);

            Console.WriteLine(beverage3.Description + " $ " + beverage3.Cost());
        }
        static void Main(string[] args)
        {
            // Simulando o pedido de um Café Expresso sem condimentos
            Beverage b1 = new Espresso();
            Console.WriteLine(b1.GetDescription() + " - R$ " + b1.Cost());

            // Simulando o pedido de um Café DarkRoast com duplo Moca (chocolate) e creme
            Beverage b2 = new DarkRoast();
            b2 = new Mocha(b2);
            //b2 = new Mocha(b2);
            b2 = new Whip(b2);
            Console.WriteLine(b2.GetDescription() + " - R$ " + b2.Cost());

            // Simulando o pedido de um Café HouseBlend com Moca, soja e creme
            Beverage b3 = new HouseBlend();
            b3 = new Soy(b3);
            b3 = new Mocha(b3);
            b3 = new Whip(b3);
            Console.WriteLine(b3.GetDescription() + " - R$ " + b3.Cost());

            Console.ReadKey();
        }
Exemple #15
0
        static void Main(string[] args)
        {
            Beverage beverage = new Espresso();

            Console.WriteLine(beverage.GetDescription() + " $" + beverage.Cost());

            Beverage beverageDark = new DarkRoast();

            beverageDark = new Mocha(beverageDark);
            beverageDark = new Mocha(beverageDark);
            beverageDark = new Whip(beverageDark);
            Console.WriteLine(beverageDark.GetDescription() + " $" + beverageDark.Cost());

            Beverage beverageHouse = new HouseBlend();

            beverageHouse = new Mocha(beverageHouse);
            beverageHouse = new Soy(beverageHouse);
            beverageHouse = new Whip(beverageHouse);
            Console.WriteLine(beverageHouse.GetDescription() + " $" + beverageHouse.Cost());

            Console.ReadLine();
        }
Exemple #16
0
        static void Main(string[] args)
        {
            BaseBeverage beverage = new Espresso();

            Console.WriteLine(beverage.Description + " $" + beverage.Cost().ToString("0.##"));

            BaseBeverage beverage2 = new DarkRoast();

            beverage2 = new Mocha(beverage2);
            beverage2 = new Mocha(beverage2);
            beverage2 = new Whip(beverage2);
            Console.WriteLine(beverage2.Description + " $" + beverage2.Cost().ToString("0.##"));

            BaseBeverage beverage3 = new HouseBlend();

            beverage3.Size = BaseBeverage.BeverageSize.Venti;
            beverage3      = new Soy(beverage3);
            beverage3      = new Mocha(beverage3);
            beverage3      = new Whip(beverage3);
            Console.WriteLine(beverage3.Description + " $" + beverage3.Cost().ToString("0.##"));

            Console.ReadKey();
        }
Exemple #17
0
        static void Main(string[] args)
        {
            Beverage beverage = new Espresso();

            Console.WriteLine(beverage.GetDescription() + ": " + beverage.Cost().ToString());

            Beverage beverage2 = new DarkRoast();

            beverage2 = new Mocha(beverage2);
            beverage2 = new Mocha(beverage2);
            beverage2 = new Whip(beverage2);

            Console.WriteLine(beverage2.GetDescription() + ": " + beverage2.Cost().ToString());

            Beverage beverage3 = new HouseBlend();

            beverage3 = new Soy(beverage3);
            beverage3 = new Mocha(beverage3);
            beverage3 = new Whip(beverage3);

            Console.WriteLine(beverage3.GetDescription() + ": " + beverage3.Cost().ToString());

            Console.ReadKey();
        }
        public void Espresso()
        {
            Espresso beverage = new Espresso();

            Assert.AreEqual(1.99, beverage.Cost(), DELTA);
        }
 public void Espresso()
 {
     Espresso beverage = new Espresso();
     Assert.AreEqual(1.99, beverage.Cost(), DELTA);
 }