Is this the best approch to combine 2 Interfaces? I have a use case where I want to use both HttpRequestInterceptor and HttpResponseInterceptor in one class.


I'm asking if the following would be a good solution and what are the potential problems?

public interface HttpRequestResponseInterceptor extends HttpRequestInterceptor, HttpResponseInterceptor {}



Then I implement this interface:

public class AuthenticatingResponseInterceptor implements HttpRequestResponseInterceptor{

  private static final String TAG = AuthenticatingResponseInterceptor.class.getSimpleName();

  @Inject
  private Authenticator authenticator;
  @Inject
  private CookieStore cookieStore;
  @Inject
  private RequestCache requestCache;

  @Override
  public void process(HttpResponse httpResponse, HttpContext httpContext) throws HttpException, IOException {
    //Implementation
  }

  @Override
  public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {
    //Implementation
  }
}



The part I am unsure about it is when I pass this into 2 separate methods:

@Inject
private HttpRequestResponseInterceptor interceptor;

httpClient.addResponseInterceptor(interceptor);
httpClient.addRequestInterceptor(interceptor);


I should probably point out that the HttpRequestResponseInterceptor is a singleton. Is this a good solution?
You don't necessarily need to have another interface that extends the two you want to combine, you just have to say that he class implements both of them.  One java class can implement as many interfaces as you desire.  

Problems may arise if you have any shared data problems, but by saying you are implementing the interface you are guaranteeing that the class has the specified functions.



import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class MyClass{


    public interface Combined extends Runnable, Callable&lt;Object&gt; {}

public class Mixed implements Runnable, Callable&lt;Object&gt; {

    @Override
    public Mixed call() throws Exception {
        System.out.println("Called Mixed");
        return this;
    }

    @Override
    public void run() {
        System.out.println("Ran Mixed");
    }

}

public class Single implements Combined{
    @Override
    public Single call() throws Exception {
        System.out.println("Called Single");
        return this;
    }

    @Override
    public void run() {
        System.out.println("Ran Single");
    }
}

/**
 * @param args
 */
public static void main(String[] args) {
    MyClass top = new MyClass();
    Mixed mixed = top.new Mixed();
    Single single = top.new Single();
    ExecutorService es = Executors.newFixedThreadPool(1);

    es.execute(mixed);
    es.execute(single);

    es.submit((Callable&lt;Object&gt;) mixed);
    es.submit((Callable&lt;Object&gt;) single);

}

}


Output is:

Ran Mixed
Ran Single
Called Mixed
Called Single