예제 #1
0
        static void Main(string[] args)
        {
            double      money = 0;
            CashContext context;

            money = Convert.ToDouble(Console.ReadLine());
            CashSuper cashNormal = new CashNormal();

            context = new CashContext(cashNormal);
            Console.WriteLine("无任何活动下收费:" + context.GetResult(money));

            CashSuper cashRebate = new CashRebate(0.8);

            context = new CashContext(cashRebate);
            Console.WriteLine("打八折的情况下收费:" + context.GetResult(money));

            CashSuper cashReturn = new CashReturn(300, 100);

            context = new CashContext(cashReturn);
            Console.WriteLine("满300送100下收费:" + context.GetResult(money));

            context = new CashContext(new List <CashSuper> {
                cashRebate, cashReturn
            });
            Console.WriteLine("先打八折,再满300 送100下收费:" + context.GetResult(money));

            context = new CashContext(new List <CashSuper> {
                cashReturn, cashRebate
            });
            Console.WriteLine("先满300 送100,再打八折:" + context.GetResult(money));

            Console.ReadKey();
        }
예제 #2
0
        public CashContext(string type)
        {
            switch (type)
            {
            case "正常收费":
                CashNormal cashNormal = new CashNormal();
                cs = cashNormal;
                break;

            case "满300减100":
                CashReturn cashReturn = new CashReturn("300", "100");
                cs = cashReturn;
                break;

            case "打八折":
                CashRebate cashRebate = new CashRebate("0.8");
                cs = cashRebate;
                break;
            }
        }
예제 #3
0
        public static CashSuper CreateCashAccept(string type)
        {
            CashSuper cs = null;

            switch (type)
            {
            case "正常收费":
                cs = new CashNormal();
                break;

            case "满300返100":
                cs = new CashReturn("300", "100");
                break;

            case "打八折":
                cs = new CashRebate("0.8");
                break;

            default:
                break;
            }
            return(cs);
        }