What are the differences between 'Find' and 'Get' verbs on methods in the Repository or Data Access Methods?
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 namin开发者_运维百科g 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!
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
throws an error if it doesn't exist (and usually only returns 1), Find
returns null (or an empty IEnumerable
).
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.
精彩评论