Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In ddd practice,Are the CRUD methods should be put in the Model Objects

I am trying to practice domain driven design,the basic structure of the code includes the following objects:

Action->Facade->
Service
Model
Repository

Where do you think the CRUD methods should be put in the Model just like the following:

order.save(new order())

Or be put in the facade just like the following:

addOrderFacade.save(new order())
like image 818
gamein Avatar asked Dec 26 '22 23:12

gamein


1 Answers

A 'save' or 'delete' method, belongs to the repository. Usually Save is called by a Service or a command handler (if you're using a command based approach to update the domain). Save handles CU from CRUD, D gets its own method , the R part is the interesting one.

WHen R means 'GetEntity' in order to update it, then it can be part of the domain repository (there is more than 1 repository) handled in the same place as the Save.

However if you want to Read to display, basicaly just queries which returns results to a user, then a different repository dedicated to queries, as well as a simplified read only model should be used. This repo can be called from the controller or even the UI.

like image 143
MikeSW Avatar answered Jan 05 '23 19:01

MikeSW