了解服务和DAO层 [英] Understanding Service and DAO layers

查看:140
本文介绍了了解服务和DAO层的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人问我一个项目的业务逻辑模块中创建的类的文档。我注意到,有些地方,创造了如何类的模式。该模式看起来像这样

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

我不明白的是为什么AService调用ADaoService方法而不是只调用ADao方法,因为ADaoService方法只是打电话ADao方法。在我看来,这ADaoService只是一个code的浪费。他们usign Hibernate和JBoss服务器。我只是新来这个类型的架构。希望有人能帮助我理解。谢谢你。

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.

推荐答案

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

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

关于未来的理由,好了,据我所知,典型的分层不包括 ADaoService 层。我在哪里工作,我们没有它。从来没有见过它的Hibernate文档...

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.

这篇关于了解服务和DAO层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆