持久层的命名约定:DAO vs Manager vs ...?
免责声明:我几乎确定我以前见过同样的问题,但现在找不到了。如果有人发现这个问题,请提供链接。
关于实现 CRUD 操作的类的最佳名称,我至少听到了两种意见:有人说 DAO 是一个经典名称,每个人都知道它的含义,但也有人说 Manager > 与 CRUD 功能对应得更好。
当我应该选择一个或另一个(或另一个)名称时,是否有任何明确的规则?
DISCLAIMER: I'm almost sure that I've seen the same question before but I can't find it now. If someone finds that question, please, give a link.
I heard at least two opinions on the best name for classes which implements CRUD operations: someone says that DAO
is a classical name and everyone knows what it means, but others say that Manager
corresponds much better to CRUD functionality.
Are there any unambiguous rules when should I choose one or another (or yet another) name?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我绝对不喜欢经理; “管理”某事可能意味着(并且被用来意味着)各种各样的事情。如果您担心人们不知道 DAO 的含义,您可以随时将其拼写为“DataAccess”。但我发现 DAO 得到了广泛的理解。
另一种方法是使用存储库模式 并调用您的类 SuchAndSuchRepository。这不一定与 DAO 相同(它可能包装一个或多个 DAO),但它可以提供一个明确命名的位置来获取对象 - 如果我想要一个 Person 对象,我知道要查找 PersonRepository 。
I definitely don't like Manager; "managing" something could mean (and is used to mean) all kinds of things. If you're afraid people won't know what DAO means, you could always spell it out as "DataAccess", say. But I find DAO to be widely understood.
Another approach is to use the Repository pattern and call your class SuchAndSuchRepository. This isn't necessarily the same thing as a DAO (it may wrap one or more DAOs) but it can provide a clearly named place to go to get your objects -- if I want a Person object, I know to look for the PersonRepository.
DAO +1。
Manager 很模糊,可以适用于 DAO 以外的许多事物。
例如,swing.DesktopManager、ErrorManager、FontManager、JavaFileManager、XMLEntityManager 是我的 IDE 工作中当前可用的 200 多个类中的一些,它们似乎与数据库持久性没有任何关系。
+1 for DAO.
Manager is vague and could apply to many things other than DAO's.
e.g. swing.DesktopManager, ErrorManager, FontManager, JavaFileManager, XMLEntityManager are some of the 200+ classes currently available in my IDE worskapce, none of which seem to have anything to do with database persistence.
我会说经理,因为任何“假设”都可能导致一些混乱。在这种情况下,我认为你假设每个人都知道 DAO。
I would say Manager, because any "assumptions" can cause some mayhem. And in this case I think you are assuming every body knows DAO.