示例#1
0
        /// <summary>
        /// 采用简单工厂来计算折扣率
        /// </summary>
        /// <param name="input">控制台输入的打折方式</param>
        /// <returns>返回应付现金</returns>
        public DiscountFather GetDis(string input)
        {
            DiscountFather dis = null;

            switch (input)
            {
            case "1":
                return(dis = new NoDiscount()); break;

            case "2":
                return(dis = new Discount2(0.9)); break;

            case "3":
                return(dis = new Discount3(500, 100)); break;
            }
            return(dis);
        }
示例#2
0
        /// <summary>
        /// 根据用户的选择返回一个打折对象
        /// </summary>
        /// <param name="realMoney">用户的选择</param>
        /// <returns>返回父类对象,但是里面装的是子类对象</returns>
        public Discount GetTotalMoney(string input)
        {
            Discount dc = null;

            switch (input)
            {
            case "1":
                dc = new DiscountNone();
                break;

            //此时需要GET
            case "2":
                dc = new Discount1(0.9);
                break;

            case "3":
                dc = new Discount2(300, 50);
                break;
            }
            return(dc);
        }