Beispiel #1
0
 private static Coffee ChoseOthers(Coffee entity)
 {
     //获取配料有哪些
     Coffee[] otherObj = new Coffee[] { new Mocha(entity), new Whip(entity), new Milk(entity) };
     while (true)
     {
         Console.WriteLine("请输选择您想要购买的咖啡的数字,输入0退出选择配料!:");
         for (int i = 0; i < otherObj.Length; i++)
         {
             Console.Write("{0}.{1}    ", i + 1, others[i]);
         }
         //接收选择的配料
         Console.WriteLine();
         int choseOther;
         int.TryParse(Console.ReadLine(), out choseOther);
         if (choseOther > coffees.Length)
         {
             Console.WriteLine("请正确输入范围内的咖啡,输入0退出选择配料!");
             continue;
         }
         else if (choseOther == 0)
         {
             Console.WriteLine("返回上一级中...");
             break;
         }
         else
         {
             //获取配料
             entity       = otherObj[choseOther - 1];
             entity.Price = otherPrice[choseOther - 1];
             //选择配料
             entity = ChoseOthers(entity);
             break;
         }
     }
     return(entity);
 }
Beispiel #2
0
 /// <summary>
 /// 注入方法
 /// </summary>
 /// <param name="coffee"></param>
 public Decorator(Coffee coffee)
 {
     this.decor = coffee;
 }
Beispiel #3
0
        /// <summary>
        /// 和父类一致的构造函数,给父类的构造函数传入参数coffee,完成注入
        /// </summary>
        /// <param name="coffee"></param>
        public Mocha(Coffee coffee) : base(coffee)
        {

        }
Beispiel #4
0
        /// <summary>
        /// 和父类一致的构造函数,给父类的构造函数传入参数coffee,完成注入
        /// </summary>
        /// <param name="coffee"></param>
        public Whip(Coffee coffee) : base(coffee)
        {

        }
Beispiel #5
0
        /// <summary>
        /// 构造函数给父类的构造函数赋值
        /// </summary>
        /// <param name="coffe">注入的具体咖啡</param>
        public Milk(Coffee coffe) : base(coffe)
        {

        }