Java Reference
In-Depth Information
Another drawback of using view interfaces is that they do not help when the
presentation tier needs a value that is computed by a method that can only be
called by the business tier. In this situation, the business tier must call the method
and return the result to the presentation tier using either a DTO , which we are try-
ing to avoid using, or an adapter, which we will discuss next.
Implementing the interfaces with adapters
For example, suppose that the presentation tier could call any of the PendingOrder 's
getters except for the getTotal() method, which retrieves the pricing and discount
information from the database. We can encapsulate the PendingOrder using the
interface we saw earlier, except that the interface is implemented by a Pending-
OrderAdapter class, which stores a reference to the real PendingOrder and the total
computed by the business tier. All of its methods delegate to the PendingOrder
except for the getTotals() method, which returns the total stored in the field:
public class PendingOrderAdapter implements PendingOrderDetail {
private PendingOrder pendingOrder;
private double total;
public PendingOrderAdapter(PendingOrder pendingOrder,
double total, …) {
this.pendingOrder = pendingOrder;
this.total = total;
}
B Stores
PendingOrder and total
public Coupon getCoupon() {
return pendingOrder.getCoupon();
}
C Delegates to
PendingOrder
public Address getDeliveryAddress() {
return pendingOrder.
b bbbbbbbbb getDeliveryAddress();
}
public RestaurantDetail getRestaurant() {
return pendingOrder.getRestaurant();
}
D Returns value
from total field
public double getTotal() {
return total;
}
}
 
 
Search WWH ::




Custom Search