Beispiel #1
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            //利用簡單工廠模式根據下拉選擇框,生成相應的物件
            CashSuper csuper      = CashFactory.createCashAccept(cbxType.SelectedItem.ToString());
            double    totalPrices = 0d;

            //透過多型,可以得到收取費用的結果
            totalPrices = csuper.acceptCash(Convert.ToDouble(txtPrice.Text) * Convert.ToDouble(txtNum.Text));
            total       = total + totalPrices;
            lbxList.Items.Add("單價:" + txtPrice.Text + " 數量:" + txtNum.Text + " "
                              + cbxType.SelectedItem + " 合計:" + totalPrices.ToString());
            lblResult.Text = total.ToString();
        }
 //得到現金促銷計算結果(利用了多型機制,不同的策略行為導致不同的結果)
 public double GetResult(double money)
 {
     return(cs.acceptCash(money));
 }