私は、貯蓄口座、小切手口座、および簡単な貯蓄口座を含む銀行口座をC#で実装しています。すべての口座に所有者と残高があり、それらのすべてが引き出して入金できますが、残高以上の引き出しはできません。ここまで、とても簡単です。さて、私たちの貯蓄口座には、新しい方法のapplyInterestとcheckingsAccountメソッドdeductFeesとeasySavinAccountの両方があります。私が考えたのは、抽象クラスAccountを使用しています。銀行モジュールに最適なモデルを実装する
public abstract class Account
{
protected string owner { get; set; }
//always use decimal especially for money c# created them for that purpose :)
protected decimal balance { get; set; }
public void deposit(decimal money)
{
if (money >= 0)
{
balance += money;
}
}
public void withdraw(decimal money)
{
if (money > balance)
{
throw new System.ArgumentException("You can't withdraw that much money from your balance");
}
else balance -= money;
}
}
これは3つのクラスすべてに継承されます。これをより良い方法で実装するのに適したデザインパターンがありますか?特にeasySaveAccountのためにおそらく組成が助けることができますか?
ありがとうございます!
これは素晴らしいアプローチです!これは4人のギャングのデザインパターンですか?それとも、それを実装するより良い方法ですか? –
私はこれをSOLID設計原理の1つである界面分離原理に基づいて提案しました。これからいくつかのアイデアを得ることができます:https://www.codeproject.com/Articles/822791/Developing-MVC-applications-using-SOLID -principles – micky