Imagine two aggregates Product
and Order
. An Order
instance can have multiple Product
s as order line items and this association is done using an OrderLine
class.
Here are the classes:
public class Order {
.
.
Set<OrderLine> orderLines;
public void addProductToOrder(Product product) {
...
}
.
.
}
public class Product {
.
.
int stock
boolean isProductOutOfStock(int quantity) {
return stock - quantity < 0;
}
.
.
}
Now imagine the scenario where I want to add a product
to an Order
. So the application service method would be something like:
{
order.addProductToOrder(Product product);
}
- Given that an aggregate (by definition) must hold its own invariants only the
product.isProductOutOfStock
check insideorder.addProductToOrder
is not advised. - Application service should not make business decisions so the check cannot be there either.
The question is: is this a good place to create adomain service
?