Java Reference
In-Depth Information
Fancy Foods
Fancy Foods
Fancy Foods
special offer
Figure 2.14 The backend of the Fancy Foods application. Triangles represent service dependencies, with
the broad end of the triangle facing the consumers of the service. There isn't a direct dependency between
the chocolate department and the offer aggregator, but the offer aggregator does consume a service pro-
vided by the chocolate department.
of them more or less at random. The order in which services get returned, and there-
fore the one you get, can be influenced by specifying a ranking in the Blueprint ser-
vice definition. Finer control can also be achieved using service properties, but for
now we're happy to accept every offer in whatever order it arrives.
Getting into the service-oriented frame of mind
Both of these operations take in a list of special offers and then return a modified list,
which is then used as input to the next adjustment. If you're keen on abstraction, you
may already be thinking that each adjustment could be represented as an instance of
an OfferListAdjuster interface:
public interface OfferListAdjuster {
public List<SpecialOffer> adjust(List<SpecialOffer> offers);
With this change, the offer aggregator no longer needs to include the code for indi-
vidual adjustments to the offer list:
public List<SpecialOffer> getCurrentOffers() {
OfferListAdjuster[] adjusters = new OfferListAdjuster[] {
new OfferSorter(), new OfferTrimmer() };
for (OfferListAdjuster adjuster : adjusters) {
offers = adjuster.adjust(offers);
return offers;
Search WWH ::

Custom Search