2012-08-16 138 views
4

我被要求在项目的业务逻辑模块中创建类的文档。我注意到有关于如何创建类的模式。该模式如下了解服务和DAO层

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)); 
      } 
    } 

我不明白的是为什么AService调用ADaoService方法,而不是仅仅调用自ADaoService方法ADAO方法只是打电话ADAO方法。在我看来,ADaoService只是代码的浪费。他们正在使用Hibernate和JBoss服务器。我只是这种类型的体系结构的新手。希望有人能帮助我理解。谢谢。

回答

8

好吧,如果ADaoService正在做什么,但委托给ADao调用,那么显然你是对的 - 它在此刻没有存在的理由

关于未来的理由,好吧,AFAIK,典型的分层不包括ADaoService层。我工作的地方我们没有。在休眠文档中从未见过它...

要么你的架构师慷慨的层次,或者他们有一些非典型的想法。

如果当前没有图层的用法,也没有明确的未来用法 - 那么最好不用它。