这一切都是......
命名空间Proxy_Pattern { 公共部分类Form1:表格 { 公共Form1() { 的InitializeComponent(); } double bankAmount = 1000.00;
private void btnCheck_Click(object sender, EventArgs e)
{
double amount;
amount = double.Parse(txtAmount.Text);
CheckProxy cp =new CheckProxy();
cp.CheckTransactionRequest(amount);
lbltotal.Text = bankAmount.ToString();
}
private void btnCreditCard_Click(object sender, EventArgs e)
{
}
}
abstract class BankSubject
{
public abstract void CreditTransactionRequest(double amount);
public abstract void CheckTransactionRequest(double amount);
}
class RealBankSubject : BankSubject
{
double bank;
public RealBankSubject(double m_bacc)
{
bank = m_bacc;
}
public override void CreditTransactionRequest(double num)
{
bank -= num;
}
public override void CheckTransactionRequest(double num)
{
bank += num;
}
}
不实现继承的抽象成员....但为什么? class CreditCardProxy:BankSubject { RealBankSubject realSubject; 双倍金额;
public CreditCardProxy (double m_bacc)
{
amount = m_bacc ;
}
没有合适的方法来覆盖?...这是一个错误怎么办?我有一个方法吗?
public override void CreditTransactionRequest()
{
if (realSubject == null)
{
realSubject = new RealBankSubject(amount);
}
realSubject.CreditTransactionRequest(amount);
}
public override void CheckTransactionRequest()
{
}
}
class CheckProxy : BankSubject
{
RealBankSubject realSubject;
double amount;
public override void CreditTransactionRequest()
{
}
public override void CheckTransactionRequest()
{
if (realSubject == null)
{
realSubject = new RealBankSubject(amount);
}
realSubject.CheckTransactionRequest(amount);
}
}
}
答案 0 :(得分:0)
CreditTransactionRequest
中的{p> CreditCardProxy
不接受任何参数,但CreditTransactionRequest
中BankSubject
的参数不同。这就是为什么你不能覆盖签名不匹配的方法。
答案 1 :(得分:0)
在您的代理中,您没有将金额指定为方法的参数:
public override void CreditTransactionRequest();
所以它无法覆盖
public abstract void CreditTransactionRequest(double amount);
因为方法签名不匹配