“查找”和“查找”之间有什么区别?并“获取”存储库或数据访问方法中的方法上的动词?
无论是使用带有接口的存储库模式还是仅在应用程序中实现 DataAccess 方法,我经常会看到在方法描述之前带有“Get”或“Find”动词的方法。我在区分 (2) 方面遇到了一些困难,因为在查看 DDD 存储库示例或使用类似命名约定的任何其他架构时,我看到了相互冲突的示例。例如,看一下下面的内容:
Function FindAllEmployees() As List(Of Employee)
Function GetAllEmployees() As List(Of Employee)
我们不要太仔细地看“Employee”这个主题,它只是一个例子;它可以是任何东西。我真的很感兴趣是否有一些关于何时在开头使用“获取”和“查找”动词来描述方法的指南。
谁能解释一下或者详细说明一下吗?谢谢!
Whether using the Repository pattern with an Interface or just implementing DataAccess methods in an application, I often see methods with either a 'Get' or 'Find' verb preceding the method description. I struggle a bit with differentiating between the (2), because I see conflicting examples when looking at DDD repository examples, or any other Architecture using a similar naming convention. For example take a look at the following:
Function FindAllEmployees() As List(Of Employee)
Function GetAllEmployees() As List(Of Employee)
Let's not look too closely at the subject of 'Employee', it is just an example; it could be anything. I am really interested if there are some guidelines on when to describe a method with a 'Get' vs. a 'Find' verb at the beginning.
Can anyone explain this or elaborate please? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对我来说,FindAllEmployees 表明它可能接受一个谓词来过滤结果,而 GetAllEmployees 就会这样做,返回完整的列表。
To me, FindAllEmployees indicates that it might accept a predicate with which to filter the results, whereas GetAllEmployees would do just that, return the complete list.
如果不存在,
Get
会抛出错误(通常只返回 1),Find
返回 null(或空的IEnumerable
)。不确定这是否具有普遍性——但对我来说很清楚。
GetById
、GetByName
等假定存在匹配项(通常是单个匹配项)。FindByEmail
、FindByDepartment
不做这样的假设,通常返回 0:n 匹配。我可能会对像
GetAll
这样不带参数并返回 1:n 匹配的方法设置异常,但在 0 时抛出异常。Get
throws an error if it doesn't exist (and usually only returns 1),Find
returns null (or an emptyIEnumerable
).Not sure if that's universal - but it's pretty clear to me.
GetById
,GetByName
, etc. presume a match exists (and usually a single match).FindByEmail
,FindByDepartment
don't presume that, and usually return 0:n matches.I may make an exception for a method like
GetAll
that takes no parameters and returns 1:n matches, but throws an exception on 0.