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):
OrderRepository
has a functionchangeState
which 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.OrderRespository
is injected intoOrder
andOrder
has functionchangeState
which will use that repository to check for conflicts - here problem is the domain object know about persistence.
What is a right way to do?