示例#1
0
        public CashContext(string type)
        {
            switch (type)
            {
            case "正常收費":
                CashNormal cs0 = new CashNormal();
                cs = cs0;
                break;

            case "滿300送100":
                CashReturn cr1 = new CashReturn("300", "100");
                cs = cr1;
                break;

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

            default:
                CashNormal csd = new CashNormal();
                cs = csd;
                break;
            }
        }
        //策略与简单工厂结合
        public CashContext(string type)
        {
            switch (type)
            {
            case "正常收费":
                CashNormal cs0 = new CashNormal();
                cs = cs0;
                break;

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

            case "打8折":
                CashRebate cr2 = new CashRebate("0.8");
                cs = cr2;
                break;
            }
        }