开发服务组件以便为服务器中的多个应用程序提供可复用的逻辑。
public interface CustomerInfo { public Customer getCustomerInfo(String customerID); }
public class CustomerInfoImpl implements CustomerInfo { public Customer getCustomerInfo(String customerID) { Customer cust = new Customer(); cust.setCustNo(customerID); cust.setFirstName("Victor"); cust.setLastName("Hugo"); cust.setSymbol("IBM"); cust.setNumShares(100); cust.setPostalCode(10589); cust.setErrorMsg(""); return cust; } }
public interface StockQuote { public float getQuote(String symbol); }
public class StockQuoteImpl implements StockQuote { public float getQuote(String symbol) { return 100.0f; } }
public interface StockQuoteAsync { // deferred response public Ticket getQuoteAsync(String symbol); public float getQuoteResponse(Ticket ticket, long timeout); // callback public Ticket getQuoteAsync(String symbol, StockQuoteCallback callback); }
public interface StockQuoteCallback { public void onGetQuoteResponse(Ticket ticket, float quote); }