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?
0
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
2