I read system codes and try to understand service level design.
I noticed that for each object (the object that will be stored in the database) a set of related classes / implementations will be created:
- Product.java
- ProductDAO.java (interface class)
- ProductDAOImpl.java
- ProductService.java (interface class)
- ProductServiceImpl.java
Based on an example shopping cart for each product purchased by a customer, I will have to complete the following transaction:
- Reduce the amount of product
- Save Order
- Create a notification entry for a batch job to send an email to notify the customer
How do I create / implement it?
Method # 1
public class ShoppingCartPageBeanA {
private ProductService productService;
private OrderService orderService;
private NotificationService notificationService;
public void submit() {
productService.decreaseProductTotalQuantity(product);
orderService.saveOrder(order);
notificationService.saveNotification(notification);
}
}
Method # 2
public class ShoppingCartPageBeanB {
private ShoppingCartService shoppingCartService;
public void submit() {
shoppingCartService.saveOrder(order);
}
}
public class ShoppingCartServiceImpl {
private ProductDAO productDAO;
private OrderDAO orderDAO;
private NotificationDAO notificationDAO;
public void saveOrder(Order order) {
productDAO.decreaseProductTotalQuantity(order.getProduct);
orderDAO.saveOrder(order);
notificationDAO.saveNotification(order.getNotification);
}
}