Java Reference
In-Depth Information
the data that it displays to the user. To begin the process of writing the business
logic, we must identify the methods that are called by the domain model's client
and determine its parameters, its return type, and the class to which it belongs.
For each request, we typically define a service method that does the bulk of the
work, including validating the request, performing calculations, and updating the
database. We also define other entity and repository methods that return data to
display. To see how to do this, let's identify the methods that the domain model
classes must define to handle the enter delivery info request. The Food to Go appli-
cation processes this request in two steps. First, it must verify that delivery infor-
mation and update PendingOrder . Second, it must display the list of available
restaurants. Let's consider each responsibility in turn.
The first responsibility belongs to the business tier because it consists of verifying
user input based on the available set of restaurants, which are presumably stored in
the database and updating PendingOrder , which is a domain object. The domain
model's client could call PendingOrder directly to verify and store the delivery
information. But as I described earlier, a domain model service is a better choice to
handle this request because it provides superior encapsulation and moves more
logic into the domain model, which simplifies the domain model's client.
This domain model does not have any services, so we need to define one.
The simplest thing to do is define a service for the Place Order use case called
PlaceOrderService . It has an updateDeliveryInfo() method, which verifies that
the delivery information is served by at least one restaurant and updates the
PendingOrder :
public interface PlaceOrderService {
bbbbbbbbb b PlaceOrderServiceResult updateDeliveryInfo(String pendingOrderId,
bbbbbbbbb b Address deliveryAddress,
bbbbbbbbb b Date deliveryTime);
}
public class PlaceOrderServiceResult {
private int statusCode;
private PendingOrder pendingOrder;
}
This code takes the pendingOrderId and delivery information as parameters. The
pendingOrderId parameter is the primary key of PendingOrder in the database,
and is stored by the presentation tier in either HttpSession or the browser. The
deliveryAddress and deliveryTime parameters contain the values entered by
the user.
 
 
 
Search WWH ::




Custom Search