电商、银行、医疗三个领域的经典分层案例,展示 domain、bo、biz 三层的协作关系:
案例1:电商订单系统
1. Domain层(领域模型)
// domain/entity/Order.java
public class Order {
private String orderId;
private List<OrderItem> items;
private OrderStatus status;
// 领域行为:计算订单总价
public BigDecimal calculateTotal() {
return items.stream()
.map(item -> item.getPrice().multiply(item.getQuantity()))
.reduce(BigDecimal.ZERO, BigDecimal::add);
}
}
2. BO层(业务对象)
// bo/OrderBO.java
public class OrderBO {
private Order order;
private InventoryService inventoryService;
// 业务逻辑:校验库存并预留
public void reserveInventory() {
if (!inventoryService.checkStock(order.getItems())) {
throw new BusinessException("库存不足");
}
}
}

最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



