Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 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!

like image 928
atconway Avatar asked Oct 10 '11 21:10

atconway


People also ask

When to use Get or find?

use "get" for a method which returns a cheaply available piece of information (and can probably be inlined or otherwise optimized away), or for a piece of information uniquely owned by this object. use "find" for a method which does work to get a piece of information, or uses other objects to find it.

Should method names be verbs?

Methods should be verbs, in mixed case with the first letter lowercase, with the first letter of each internal word capitalized. Except for variables, all instance, class, and class constants are in mixed case with a lowercase first letter. Internal words start with capital letters.

Is fetch and get the same?

I think fetch is usually more polite when requesting that somebody brings you something: "fetch me that book" is a request, whereas "get me that book" sounds like an order. Obtained can also be used to simply mean that you came into possession of something—not necessarily that you got it yourself.


1 Answers

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.

like image 94
Jason Miesionczek Avatar answered Nov 15 '22 10:11

Jason Miesionczek