DDD Approach to Access External Information

前端 未结 4 1275
遇见更好的自我
遇见更好的自我 2020-11-30 11:58

I have an existing bank application classes as shown below. The banks account can be of SavingsBankAccount or FixedBankAccount. There is an operation called IssueLumpSumInte

4条回答
  •  醉话见心
    2020-11-30 12:52

    2 min scan answer..

    • Not sure why there is a need for 2 representations of a BankAccount RepositoryLayer.BankAccount and DomainObjectsForBank.IBankAccount. Hide the persistence layer coupled one.. deal with just the domain object in the service.
    • Do not pass/return Nulls - I think is good advice.
    • The finder methods look like the LINQ methods which select items from a list of collection. Your methods look like they want to get the first match and exit..in which case your parameters can be simple primitives (Ids) vs lambdas.

    The general idea seems right. The service encapsulates the logic for this transaction - not the domain objects. If this changes, only one place to update.

    public void IssueLumpSumInterest(int acccountID)
    {
        var customerId = accountRepository.GetAccount(accountId).CustomerId;
    
        var accounts = accountRepository.GetAccountsForCustomer(customerId);
        if ((accounts.First() is FixedAccount) && accounts.Count() == 1)
        {
           // update interest    
        }
    }
    

提交回复
热议问题