Ejemplo n.º 1
0
        /// <summary>
        ///  步骤 7 BuiderPatternDemo 使用 MealBuider 来演示建造者模式(Builder Pattern)。
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            MealBuilder mealBuilder = new MealBuilder();

            Meal vegMeal = mealBuilder.PrepareVegMeal();

            Console.WriteLine("Veg Meal");
            vegMeal.ShowItems();
            Console.WriteLine("Total Cost: " + vegMeal.GetCost());

            Meal nonVegMeal = mealBuilder.PrepareNonVegMeal();

            Console.WriteLine("\n\nNon-Veg Meal");
            nonVegMeal.ShowItems();
            Console.WriteLine("Total Cost: " + nonVegMeal.GetCost());
            Console.ReadKey();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 步骤7 使用MealBuilder 来演示建造者模式
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            MealBuilder builder = new MealBuilder();
            Meal        vegMeal = builder.PrepareVegMeal();

            Console.WriteLine("素套餐");
            vegMeal.ShowItems();
            Console.WriteLine("总价:" + vegMeal.GetCost());

            Meal nonVegMeal = builder.PrepareNonVegMeal();

            Console.WriteLine("荤套餐");
            nonVegMeal.ShowItems();
            Console.WriteLine("总价:" + nonVegMeal.GetCost());

            Console.ReadKey();
        }