Question

I have a question:

I have a domain : LoanAccount. We have different product of loans but they just different on how to calculate the interest.

for example: 1. Regular Loan calculate interest rate using Annuity Interest Rate formula 2. Vehicle Loan calculate interest rate using Flat Interest Rate formula 3. Temporary Loan calculate interest rate with another formula (i have no idea what is that).

We also could change the rule every year ... we use different formula as well ...

My Question: Should I put all the logic formula in services ? Should I make every loan in different domain class ? or should I make 1 domain class but it has different interest rate calculation methods ?

Any example would be good :) Thank you in advance !

Était-ce utile?

La solution

My suggestion is to separate interest calculating logic from the domain objects. Hard-wiring the domain object and it's interest calculation is likely to lead you in trouble.

  • It would be more complicated to change the type of interest calculation for existing account type (which could be expected business request)
  • When new account type is created you can easily use all the calculation methods you have already implemented for it
  • It's likely that interest-calculating algorithm will grow in complexity in the future and it may need properties that should not be part of Account domain object, like some business constants, list of transactions etc.
  • Grails (because Spring) naturally supports to have business logic in services (declarative transactions etc.) rather than in the domain objects. You will always have less pain when going along with the framework than otherwise.
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top