Is there anything bad in declaring static inner class inside interface in java?
- by Roman
I have an interface ProductService with method findByCriteria. This method had a long list of nullable parameters, like productName, maxCost, minCost, producer and so on.
I refactored this method by introducing Parameter Object. I created class SearchCriteria and now method signature looks like this:
findByCriteria (SearchCriteria criteria)
I thought that instances of SearchCriteria are only created by method callers and are only used inside findByCriteria method, i.e.:
void processRequest() {
SearchCriteria criteria = new SearchCriteria ()
.withMaxCost (maxCost)
.......
.withProducer (producer);
List<Product> products = productService.findByCriteria (criteria);
....
}
and
List<Product> findByCriteria(SearchCriteria criteria) {
return doSmthAndReturnResult(criteria.getMaxCost(), criteria.getProducer());
}
So I did not want to create separate public class for SearchCriteria and put it inside ProductServiceInterface:
public interface ProductService {
List<Product> findByCriteria (SearchCriteria criteria);
static class SearchCriteria {
...
}
}
Is there anything bad in this interface? Where whould you place SearchCriteria class?