コード例 #1
0
        public static void RunStarBuck()
        {
            Console.WriteLine("StarBuck Coffe Order: ");

            Beverage beverage = new Espresso();

            Console.WriteLine(string.Format("{0} : ${1}", beverage.GetDescription(), beverage.GetCost()));

            Beverage beverage2 = new DarkRoast();

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

            Console.WriteLine(string.Format("{0} : ${1}", beverage2.GetDescription(), beverage2.GetCost()));
        }
コード例 #2
0
        static void Decorator()
        {
            Beverage beverage1 = new Espresso();

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

            Beverage beverage2 = new Espresso();

            beverage2 = new Mocha(beverage2);
            Console.WriteLine(beverage2.GetDescription());
            Console.WriteLine(beverage2.GetCost());

            Beverage beverage3 = new Espresso();

            beverage3 = new Mocha(beverage3);
            beverage3 = new Whip(beverage3);
            Console.WriteLine(beverage3.GetDescription());
            Console.WriteLine(beverage3.GetCost());
        }
コード例 #3
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.A))
        {
            ICoffee coffee = new Espresso();
            Debug.Log("Coffee discription and cost: " + coffee.GetDescription() + " $" + coffee.GetCost());
        }

        if (Input.GetKeyDown(KeyCode.S))
        {
            ICoffee coffee = new Filtered();
            Debug.Log("Coffee discription and cost: " + coffee.GetDescription() + " $" + coffee.GetCost());
        }

        if (Input.GetKeyDown(KeyCode.D))
        {
            ICoffee coffee = new ChocolateDecorator(new Espresso());
            Debug.Log("Coffee discription and cost: " + coffee.GetDescription() + " $" + coffee.GetCost());
        }

        if (Input.GetKeyDown(KeyCode.F))
        {
            ICoffee coffee = new ChocolateDecorator(new Filtered());
            Debug.Log("Coffee discription and cost: " + coffee.GetDescription() + " $" + coffee.GetCost());
        }

        if (Input.GetKeyDown(KeyCode.Z))
        {
            ICoffee coffee = new MilkDecorator(new Espresso());
            Debug.Log("Coffee discription and cost: " + coffee.GetDescription() + " $" + coffee.GetCost());
        }

        if (Input.GetKeyDown(KeyCode.X))
        {
            ICoffee coffee = new MilkDecorator(new Filtered());
            Debug.Log("Coffee discription and cost: " + coffee.GetDescription() + " $" + coffee.GetCost());
        }

        if (Input.GetKeyDown(KeyCode.C))
        {
            ICoffee coffee = new ChocolateDecorator(new MilkDecorator(new Filtered()));
            Debug.Log("Coffee discription and cost: " + coffee.GetDescription() + " $" + coffee.GetCost());
        }

        if (Input.GetKeyDown(KeyCode.V))
        {
            ICoffee coffee = new ChocolateDecorator(new MilkDecorator(new Espresso()));
            Debug.Log("Coffee discription and cost: " + coffee.GetDescription() + " $" + coffee.GetCost());
        }
    }