In my previous blog, I provided an architecture overview of the Spring framework. In this blog, I will follow it up with a simple example of using IOC using Spring. The complete source code for the application is available for download here. However, in this blog we would build the code from scratch.
I’ll take the use case of online credit card enrollment that we have discussed earlier in Part 1. With respect to the implementation, the credit card enrollment requires that the user interact with the following services:
- A credit rating service that queries the user’s credit history information
- A remote credit linking service that inserts and links customer information with credit card and bank information for the purpose of automatic debits (if required)
- An e-mail service that e-mails the user about the status of his credit card
For this example, I assume that the services already exist and that it is desirable to integrate them in a loosely coupled manner. The listing 1 below show the application interfaces for the three services.
Listing 1. CreditRatingInterface
public interface CreditRatingInterface { public boolean getUserCreditHistoryInformation(ICustomer iCustomer); }
The credit rating interface shown in Listing 1 provides credit history information. It requires a Customer object containing customer information. The implementation is provided by the CreditRating class.
Listing 2. CreditLinkingInterface
public interface CreditLinkingInterface { public String getUrl(); public void setUrl(String url); public void linkCreditBankAccount() throws Exception ; }
The credit linking interface links credit history information with bank information (if required), and inserts credit card information for the user. The credit linking interface is a remote service whose lookup is made through the getUrl() method. The URL is set by the Spring framework’s beans configuration mechanism, which I discuss later. The implementation is provided by the CreditLinking class. (more…)