In my company we have a very specific pricing strategy:
- Every
Productin our catalog has abaseUsdPrice, for example product Foo has base USD price of 9.99$. - That does not necessary mean that will be your you'll be paying 9.99$. We check your country for price exceptions - for example in GB Foo costs 8.99$
- Further more you can choose a currency you want to pay - if you're in GB you can pay in either USD (mentioned 8.99$) or your local currency (in this case GBP).
- If you choose to pay by your local currency we calculate an equivalent of 8.99$ to british pounds based on fixed price matrix (for example here that'll be 3.99£)
- This the price you pay.
How should I design my Product aggregate root in DDD manner to be clean, cohesive, decoupled and easy to change?
- Should
paymentPricebe calculated by domain service and its result put as a part ofProductaggregate? If so that means myProductRepositorywill have methods likeproduct(productId, countryId, currency) - Should I put all calculations in domain service class
PaymentPriceCalculatorand use visitor pattern likegetPaymentPrice(Country, Currency)? What if I need to usepaymentPricefrom my entity to perform some business rule checks?
I'm trying to wrap my head around it and I think I'm overthinking it and it hurts. ;)
Decoratorpattern to wrap your objects (users) with your functionality (methods) and use aFactory Patternto roll-out the different types of objects (users). - Drew Kennedy