David_W (70) [Avatar] Offline
#1
If you have addProduct and removeProduct update the repository, what happens if you have a UI where the user creates the order (involving calls to add/remove), and then decides to cancel? When they cancel, you would have to revert the state of the order and inventory. In addition, presumably you want some kind of validation involved (eg, maximum order value linking to payment method). I would have just included a save method on Order that updates the repository if all validation passes.
David_W (70) [Avatar] Offline
#2
Re: potential problem with listing 16.15
In addition, having a save method that starts with validation would also solve your issue with the DTO in section 16.3 - you can make any changes that you want to a line item directly (assuming that the order has not been placed yet), but they won't be persisted until you save the order, and that runs validation.
ramnivas (171) [Avatar] Offline
#3
Re: potential problem with listing 16.15
It really depends on the specific requirements and the domain model. For example, if you want to provide quick feedback, then the implementation as in book will do better. As for save(), we have place() that can do the job.