Java Reference
In-Depth Information
Strategies with the Spring Framework
Although it is quite legitimate to put the business logic code in session facades, it is not
the best approach. You will be better served by moving the business logic to POJO com-
ponents and letting the session facade delegate to these POJOs. This will free up the
session facade. It can now act as the gateway to the remotely accessible business tier.
Since the business logic is now moved to POJO, it is easier to unit test. The POJO applica-
tion services sit behind the SLSB gateway and so can also leverage robust infrastructure
support such as transactions. In other words, all POJO methods that are invoked from
the session facade will be part of the same transaction scope. Moving business logic to
POJO components also reduces the effort that will be required to run an application like
eInsure in a web container.
The first step to writing an application service is to define an interface following the
P2I principle. Listing 4-21 shows the UnderwritingApplicationService interface.
Listing 4-21.
public interface UnderwritingApplicationService {
public void underwriteNewPolicy(String productCd,String name,int age);
Listing 4-22 shows the application service implementation class. Note that this class
does not use entity beans for persistence needs. Instead, it uses lightweight data access
objects for persistence. You will learn more about data access objects in Chapter 5.
Listing 4-22.
public class UnderwritingApplicationServiceImpl implements
private PolicyDetailDao policyDetailDao;
public void underwriteNewPolicy(String productCd, String name, int age) {
//business validation - is this age allowed for this product
this.policyDetailDao.savePolicyDetails(productCd, name, age);
Search WWH ::

Custom Search