Hi,
I am also a struggling recoverist from acute anemicdomainsm trying to grasp DDD (especially in the mvc/spring/orm context). I tried to partially implement a very simple domain with an Order which can add OrderRows based on Products. The "core" method in Order looks like this:
Code:
public void addOrderRow(String productName) throws DuplicateProductException, OrderAlreadyProcessedException {
if (productAlreadyInOrder(productName)) {
throw new DuplicateProductException("Product " + productName + " already in order");
}
if (orderAlreadyProcessed()) {
throw new OrderAlreadyProcessedException("Order " + orderNumber + " is already processed");
}
Product product = repositoryLocator.getProductRepository().fetchProductByProductname(productName);
OrderRow newRow = OrderRowFactory.createRow(product, rows.size() + 1);
rows.add(newRow);
}
* Should the Product added be looked up by the Order or should the caller pass in the looked up Product?
* Should the row number be passed to the OrderRowFactory in that way?
And the calling action looks something like
Code:
public void addProductToOrder() {
try {
currentOrder.addOrderRow(selectedProductName);
serviceLocator.getPersistenceService().persist(currentOrder);
} catch (DuplicateProductException e) {
e.printStackTrace();
} catch (OrderAlreadyProcessedException e) {
e.printStackTrace();
}
}
* Should the persistance be the responsibilty of the callee?
* Should the repositories do all their DB access through a DAO or can they have a DAO-like implementation themselves? (please see attached code)
Please see the attached zip for "complete" source. e.g. it compiles but hasn't been run in any way.
JPA and spring mappings have been left out and there are many simplifications but hopefully you get the point. The post would be too long if I posted them all in text.
Am I at all heading in the right direction regarding the design and dao/repository/service concepts? Comments are appreaciated!