Note that there are some explanatory texts on larger screens.

plurals
  1. POIs there anything bad in declaring nested class inside interface in java?
    text
    copied!<p>I have an interface <code>ProductService</code> with method <code>findByCriteria</code>. This method had a long list of nullable parameters, like <code>productName</code>, <code>maxCost</code>, <code>minCost</code>, <code>producer</code> and so on.</p> <p>I refactored this method by introducing <a href="http://www.refactoring.com/catalog/introduceParameterObject.html" rel="nofollow noreferrer">Parameter Object</a>. I created class <code>SearchCriteria</code> and now method signature looks like this:</p> <pre><code>findByCriteria (SearchCriteria criteria) </code></pre> <p>I thought that instances of <code>SearchCriteria</code> are only created by method callers and are only used inside <code>findByCriteria</code> method, i.e.:</p> <pre><code>void processRequest() { SearchCriteria criteria = new SearchCriteria () .withMaxCost (maxCost) ....... .withProducer (producer); List&lt;Product&gt; products = productService.findByCriteria (criteria); .... } </code></pre> <p>and</p> <pre><code>List&lt;Product&gt; findByCriteria(SearchCriteria criteria) { return doSmthAndReturnResult(criteria.getMaxCost(), criteria.getProducer()); } </code></pre> <p>So I did not want to create a separate public class for <code>SearchCriteria</code> and put it inside <code>ProductServiceInterface</code>:</p> <pre><code>public interface ProductService { List&lt;Product&gt; findByCriteria (SearchCriteria criteria); static class SearchCriteria { ... } } </code></pre> <p>Is there anything bad with this interface? Where whould you place <code>SearchCriteria</code> class?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload