I have a quite difficult problem to solve.
In my model I have AR Unit
, AR Stage
and VO GoToPositionOrder
, that implements Order
interface.
It works like that:
order = GoToPositionOrder(Position(Point(3, 4)))
unit.followOrder(order)
(I can give various of orders to unit)unitRepository.store(unit)
TimeStep
is sent, I call domain service unitsFollowOrders(unitRepository.all())
Now, where is the problem? Each order does some action on given unit (command pattern) when is followed : order.execute(unit)
. Problem is that different orders needs different additional data to do its action. In example GoToPositionOrder
needs access to AR Stage
so it can find the shortest path to position. But how can I give Order
access to Stage
?
I can't simply pass a reference there, because AR should be referenced by id, for various reasons. If it's referenced by id, then to retrieve it, VO would have access to repository, and that violates SRP (single responsibility principle).
What other options do I have?
I think a Domain Service is the right place to put the pathfinding logic since that capability doesn't seem to belong in any Entity, is stateless, and needs data from multiple AR's.
It would have a FindShortestPath()
method producing a GoToPositionOrder
VO which is then injected into the Unit
. The VO would contain no logic, only the list of steps to take for the Unit
to reach its goal.