I'm building a finnancial application where i have two ways to calculate the balance of the credit so try to follow a design based on Domain Driven Design and i feel some confused respect how supose that i have to inyect the balance calculator in the credit entity. i try to insert a interface in credit called IBalanceCalculator then when i call method CalculateBalanceAtDate in the credit this determine what instance use
this is the example
credit {
protected IBalanceCalcultar _calculator;
....
private void _InitializeBalanceCalculator()
{
if (_balanceCalculator == null)
switch (InterestType)
{
case EInterestType.OutstandingBalance:
_balanceCalculator = new OutstandingBalanceService();
break;
case EInterestType.GlobalBalance:
_balanceCalculator = new GlobalBalance();
break;
default:
throw new Exception();
}
}
public void CalculateBalanceAtDate(DateTime date, bool moratory)
{
_InitializeBalanceCalculator();
_balanceCalculator.GetBalance(this, date);
}
}
but i feel that this way is not so good
someone can clarify me is correct or if exists a better way
Aucun commentaire:
Enregistrer un commentaire