title: Generic Interface
body: <p>Let's say I wanted to define an interface which represents a call to a remote service. Now, the call to the remote service generally returns something, but might also include input parameters. Suppose that an implementing class will typically only implement one service method. Given the above information, is the following a poor design (it doesn't quite feel right):</p>
  
  <pre><code>public interface IExecutesService&lt;A,B&gt;
  {
      public A executeService();
      public A executeService(B inputParameter);
  }
  </code></pre>
  
  <p>Now, let's say that I implement this interface with a class that executes a remote service with an input parameter:</p>
  
  <pre><code>public class ServiceA implements IExecutesService&lt;String,String&gt;
  {
    public String executeService()
    {
      //This service call should not be executed by this class
      throw new IllegalStateException("This method should not be called for this class...blabla");
    }
  
    public String executeService(String inputParameter)
    {
      //execute some service
    }
  </code></pre>
  
  <p>I have two questions regarding the above:</p>
  
  <ol>
  <li>Is the use of a generic interface (<code>IExecutesService&lt;A,B&gt;</code>) good in the case where you want to provide subclasses which require different input parameters and return types for the interface methods?</li>
  <li>How can I do the above better? I.e. I want to group my service executors under a common interface (<code>IExecutesService</code>); however, an implementing class will typically only implement one of the methods, and the use of an IllegalStateException feels really ugly. Also, the B type parameter in <code>IExecutesService&lt;A,B&gt;</code> will be redundant for an implementing class that calls a service without any input parameters. It also seems overkill creating two separate interfaces for the two different service calls.</li>
  </ol>