I was asked to create documentation of classes in the business logic module of a project. I noticed that there was a pattern on how the classes where created. The pattern looks like this
public class AModel(){
//fields
//getter and setters
}
public class AService(){
public void processA(AModel model){
//creates instance of AModel, assigns values to fields
//calls ADaoService methods
}
}
public class ADaoService(){
//has methods which call ADao methods
//sample
public AModel retrieveById(long id){
log.debug(...);
return (ADao.retrieveById(id));
}
}
public class ADAo(){
//has entityManager and some query
public AModel retrieveById(long id){
return((AModel) entityManager.find(AModel.class, id));
}
}
What I don’t understand is why does AService calls ADaoService methods instead of just calling ADao methods since ADaoService methods are just calling ADao methods. It seems to me that ADaoService was just a waste of code. They are usign Hibernate and JBoss server. I’m just new to this type of architecture. Hope someone can help me understand. Thanks.
Well, if
ADaoServiceis doing nothing but delegating calls toADaothen clearly you’re right – it has no existence justification at the moment.Regarding future justifications, well, AFAIK, the typical layering does not include
ADaoServicelayer. Where I work we don’t have it. Never seen it in Hibernate docs…Either your architects were generous with layers or they had some non-typical scenario in mind.
If there’s no current usages of the layer and no clear future usages – you’re better off without it.