I have the following factory class, wonder if this code can be implemented in better way. I saw few discussions about spring factory bean, but don't find good examples.
@service
public CustomerSearchFactory{
@Autowired
private CustomerSearchByID searchById;
@Autowired
private CustomerSearchByName searcyByName;
@Autowired
private CustomerSearchBySSN searchBySSN;
public CustomerSearch getInstance(Request param){
if (StringUtils.isNotBlank(param.getID()){
return searchById;
}else if (StringUtils.isNotBlank(param.getName()){
return searcyByName;
}else if (StringUtils.isNotBlank(param.getSSN()){
return searchBySSN;
}
}
}
@service
public CustomerSearchByID implements CustomerSearch{
@Autowired
private Service1 service1;
public Response search(Request request){
--
--
ReturnResponse rs = service1.performSearch(inputRequest);
--
return response;
}
}
@service
public CustomerSearchBySSN implements CustomerSearch{
@Autowired
private Service2 service2;
public Response search(Request request){
--
--
ReturnResponse rs = service2.performSSNSearch(inputRequest);
--enter code here`
return response;
}
}
caller code:
CustomerSearch customerSearch= customerSearchFactory.getInstance(param)
response = customerSearch.search(request);
I am using the spring 3.1 framework and want to know if this code can be optimized.