Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding Service and DAO layers

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.

like image 265
Frank Smith Avatar asked Feb 20 '23 11:02

Frank Smith


1 Answers

Well, if ADaoService is doing nothing but delegating calls to ADao then clearly you're right - it has no existence justification at the moment.

Regarding future justifications, well, AFAIK, the typical layering does not include ADaoService layer. 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.

like image 105
yair Avatar answered Mar 04 '23 23:03

yair