コード例 #1
0
ファイル: Form1.cs プロジェクト: maoshanli/DesignPattern
        private void button1_Click(object sender, EventArgs e)
        {
            Beverage beverage = new Espresso();

            Beverage beverage2 = new HouseBlend();

            beverage2 = new Mocha(beverage2);
            beverage2 = new Mocha(beverage2);
            beverage2 = new Whip(beverage2);
            this.richTextBox2.Text = beverage.getDescription() + "$" + beverage.cost() +
                                     "\n" + beverage2.getDescription() + "$" + beverage2.cost();
        }
コード例 #2
0
        static void Main(string[] args)
        {
            Beverage 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 Mocha(beverage3);
            beverage3 = new Whip(beverage3);
            Console.WriteLine(beverage3.Description + " $" + beverage3.cost());
        }