christian wrote:
1. Search for a pattern
2. Execute some routine depending on the result
The problem to me here is that it still feels to me like this belongs in the domain model (even though I agree that the domain model shouldn't be
directly accessing the persistence layer).
I have a problem at the moment where some of my validation envolves the number of child objects: Lets say I cant delete an Order if it contains Order Items.
So, from your approach above, our service layer would do something like this:
Code:
int orderItems = dao.countItems(order);
order.canDelete(orderItems);
However, to me, (very knew to ORM, so I know that doesn't count for much), this isn't
very far away from Anemic Domain model.
Our service layer ends up potentially knowing about every business rule!
Maybe it's ok for one specific case, but the solution seems to degrade pretty quickly as the number of business rules increases.
Unfortunately, I can't think of a much neater solution without the Domain model knowing (explicitly or implicitly) about the persistence layer.
Any thoughts?
Dave