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 "打8折": cs = new CashRebate(0.8); break; } return(cs); }
static void Main(string[] args) { CashSuper cs = CashFactory.CreateCashAccept("打8折"); Console.WriteLine(cs.AcceptCash(600)); }