I have a SearchService
which uses an algorithm for querying a database and returing the results. There are a couple of different formats the data can be returned as, depending on what the invoker wants from the service. These formats are:
Currently my SearchService looks like:
public interface SearchService {
public List<People> searchPeopleReturnEntity(SearchRequest request);
public List<Long> searchPeopleReturnId(SearchRequest request);
public List<SearchResult> searchPeopleReturnSearchResult(SearchRequest request);
}
I'm looking for advice on best practices regarding this. Currently the naming convention seems pretty clunky and I believe there is a better solution than what I have now.
I'd call them something simple like getPeople
, getIds
, getSearchResults
.
If you need these same 3 methods for entities other than people, I'd consider making some generic intermediate type defining them, allowing you to write something like this:
List<People> people = service.getPeople(request).asEntities();
List<Long> fooIds = service.getFoos(request).asIds();
// or something like this
List<People> people = service.searchPeople().getEntities(request);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With