Let's say we have a class Order (related to user) and it has property state. I want to prevent having more than one confirmed order in the same time so before I confirm any order I have to check if there is already some confirmed in it's time period.
I can make 2 approaches (I know of):
OrderRepositoryhas a functionchangeStatewhich search for conflicting confirmed orders before changing it and allows it only when nothing is found - the problem here is repository knows about logic of changing state.OrderRespositoryis injected intoOrderandOrderhas functionchangeStatewhich will use that repository to check for conflicts - here problem is the domain object know about persistence.
What is a right way to do?