Java Reference
In-Depth Information
public PlaceOrderFacadeResult make(int statusCode,
PendingOrder pendingOrder, List restaurants) {
bb initializePendingOrder(pendingOrder);
bb return new PlaceOrderFacadeResult(statusCode,
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb pendingOrder, restaurants);
}
public PlaceOrderFacadeResult make(int statusCode,
PendingOrder pendingOrder) {
bb initializePendingOrder(pendingOrder);
bb return new PlaceOrderFacadeResult(statusCode,
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb pendingOrder);
}
private void initializePendingOrder(
PendingOrder pendingOrder) {
bb Restaurant restaurant = pendingOrder
bbbbbbbb .getRestaurant();
bb if (restaurant != null) {
bb MenuItem menuItem = restaurant
bb .getMenuItems().get(0);
bb menuItem.getName();
bb }
bb List<PendingOrderLineItem> lineItems = pendingOrder
bb .getLineItems();
bb if (lineItems != null && !lineItems.isEmpty()) {
bb lineItems.get(0);
bb }
}
}
The make() methods call initializePendingOrder() , which touches the pending
order's line items and the restaurant's menu items to ensure that they are loaded.
It does not need to touch each line item's menu item because many-to-one rela-
tionships are eagerly loaded by default. As with the Hibernate version, this code
contains potentially error-prone conditional logic to handle null references and
empty collections.
A result factory is just one of the several components that a façade typically
needs to fulfill its responsibilities. Let's now look at how to assemble the façade
and those components.
 
Search WWH ::




Custom Search