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:
- I create order:
order = GoToPositionOrder(Position(Point(3, 4)))
- I give it to unit:
unit.followOrder(order)
(I can give various of orders to unit) - orders are stored in Unit and then I can store unit:
unitRepository.store(unit)
- orders that are stored in unit are followed by unit every step, until order is finished, so every time event
TimeStep
is sent, I call domain serviceunitsFollowOrders(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?