Skip to content

Instantly share code, notes, and snippets.

View m-tilab's full-sized avatar
🎯
Focusing

Mahdi Tilab m-tilab

🎯
Focusing
View GitHub Profile
...
searchService.search(ParameterObject.build()
.withType("type1")
.sortBy("ASC")
.build());
...
public class SearchService {
/* Parameter Object example. Default values are abstracted into the Parameter Object
at the time of Object creation */
public String search(ParameterObject parameterObject) {
return getQuerySummary(parameterObject.getType(), parameterObject.getSortBy(),
parameterObject.getSortOrder());
}
private String getQuerySummary(String type, String sortBy, SortOrder sortOrder) {
public class SearchService {
//Method Overloading example. SortOrder is defaulted in this method
public String search(String type, String sortBy) {
return getQuerySummary(type, sortBy, SortOrder.DESC);
}
/* Method Overloading example. SortBy is defaulted in this method. Note that the type has to be
different here to overload the method */
public String search(String type, SortOrder sortOrder) {
return getQuerySummary(type, "price", sortOrder);