2

I'm beginning working with repository pattern. When it comes to simple queries I don't have problems with names.

  • GetById
  • GetByDay
  • UpdateById

If a method retrieves data filtered by two values also I can name it properly.

  • GetByNameAndSurname

Also when there are very advanced filters I just name it as follows.

  • GetByFilter

(and pass search criteria object)

But I have a problem with naming methods like that:

  • Get data filtered by three or four values (GetByNameAndSurnameAndDayAndCountry)
  • Get data using comparison (GetByDateGreatherThan)
  • Mixed (GetByCreateDateGreatherThanAndNameAndSurname)

Is there any good pattern I can use to name such methods?

closed as primarily opinion-based by gbjbaanb, durron597, user40980, user22815, Kilian Foth Apr 23 '15 at 12:36

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.

6

Use the entire method signature to specify your intent, not just its name. Method names should represent verbs not phrases. Your method signatures can be written as:

Get(object id)
Get(Date day)
Update(object id)

Get(string name, string surname)
Get(Filter filter)

Get(string name, string surname, Date day, string country)
Get(Date greaterThan);
Get(Date greaterThan, string name, string surname)

A case where it could be needed to be more specific in a method name should be when the parameter part of the signature is identical. For example:

Get(object id); // GetById 
Get(object name); // GetByName
  • Thank you. I was familiar with this concept, but didn't like it because IMO it's not as clear as my previous approach. Though after consideration I think yours is better. Could you tell me what's your opinion about dividing Get into GetSingle and GetList? – Landeeyo Apr 22 '15 at 11:24
  • I also use this separation, since GetSingle and GetList can have the same parameters. – devnull Apr 22 '15 at 11:31

Not the answer you're looking for? Browse other questions tagged or ask your own question.