I am experimenting building software using DDD pattern. I have no problem with creating and updating data. When the user fill-up the forms, it will automatically handle by my domain if there is a business logic involve with it.
My problem is how can I retrieve the data if there is some complex logic involve upon retrieving it?
For instance, using DDD in order software with discounts,should I store the total data after my domain computation? or compute the discount when retrieving it the database?
Thanks for your explanation. (-:
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
In DDD your database is an external concern (part of the infrastructure) and plays no role in your model. In fact, the database is usually abstracted out to an interface for your Domain to use in it’s computations. You use the DB to simply store and hydrate models.
To answer your question: it depends on your UL.
For example: you might store the discounted value in the database if you needed to “save” an order and retrieve it in it’s exact state at a later time. Or maybe your Domain and UL requires users to transfer totals. For example: a balance transfer Application that allows the Application to shave a percentage off the amount transferred (it may be called a service fee). In this case, the total after the service fee is subtracted is most likely going to be saved.
Most of the time though, it’s better to compute your discount in the domain because your discount is a Domain concept.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0