Java Reference
In-Depth Information
The updateDeliveryInfo() method returns a PlaceOrderServiceResult that
contains a status code and PendingOrder . The status code indicates the outcome of
verifying the delivery information. This method returns PendingOrder because it is
needed by caller. It is, for example, displayed by the presentation tier.
The other responsibility when processing the enter delivery info request is dis-
playing the list of available restaurants. This responsibility primarily belongs to the
presentation tier because it consists of displaying data. However, the domain
model must provide a way to find the available restaurants. Finding the available
restaurants is a database query, which is encapsulated by a repository.
Because we are finding restaurants, it makes sense to add a RestaurantReposi-
tory to the domain model and make it responsible for retrieving the list of available
restaurants. We define a findAvailableRestaurants() method that takes the deliv-
ery information as a parameter and returns the list of restaurants that serve it:
public interface RestaurantRepository {
bbbbbbbbbb List findAvailableRestaurants(Address deliveryAddress,
Date deliveryTime);
}
In addition, since the presentation tier displays each restaurant's name and type,
the Restaurant class must define getters that return these values:
public class Restaurant {
public String getName() { … }
public String getType() { … }
}
The getName() method returns the name of the restaurant and the getType()
method returns its type.
The presentation tier or the façade first calls the PlaceOrderService to update
the PendingOrder and then calls RestaurantRepository to retrieve the available
restaurants. PlaceOrderService doesn't return the list of available restaurants
because, if it did, it would be tightly coupled to the UI design. It is better to decou-
ple services from the UI and let the domain model's client make extra calls to the
domain model to get the data that it needs to display. The façade or the presenta-
tion tier calls the domain model service to update the domain model and calls
repositories to get the data that is displayed to the user. It is important to remem-
ber that the domain model is invoked via local calls, and so there is no overhead
associated with multiple calls.
 
Search WWH ::




Custom Search