Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9243559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:50:05+00:00 2026-06-18T08:50:05+00:00

Premise: In my project I have two generically typed interfaces defining Request and Response

  • 0

Premise: In my project I have two generically typed interfaces defining Request and Response respectively. A request is processed to yield a response, hence every response is built based on a request. A Processor interface processes a request to build the corresponding response.

Code: The request and response interfaces are:

interface Request<T1>

and

interface Response<T2>

respectively, where T2 and T1 represent generic request and response types (I am deliberately calling them by different names for clarity).

Now, since T2 is a Request, and T1 is a response, so the above code evolves to:

interface Request<T1 extends Response>

and

interface Response<T2 extends Request>

Note that: Request and Response interfaces do not share any inheritance relationship – what the above code only intends to communicate is: Request is typed with only some other type which is-a Response.

Now, consider the Request interface: since Response is again typed, and the response built out of a request will be tied to the original request type, hence, the above code evolves to:

interface Request<T1 extends Response<? extends Request<T1>>>

and

interface Response<T2 extends Request<? extends Response<T2>>

Now, the Processor interface is defined as:

interface Processor<R1 extends Request<R2>, R2 extends Response<R1>> {
    R2 process(R1 request);
}

Concrete classes:

Request implementation:

class ConcreteRequest implements Request<ConcreteResponse> {
    ConcreteResponse response;
    ...`
}

Response implementation:

class ConcreteResponse implements Response<ConcreteRequest> {
    ConcreteRequest request;
    ...
}

Processor implementation:

class ConcreteProcessor implements Processor<ConcreteRequest, ConcreteResponse> {
    ConcreteResponse process(ConcreteRequest request) {
    ...
    }
}

Question: Is the above code over-designed? Is there a simplified way to represent a tuple of complementary input-output objects?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T08:50:06+00:00Added an answer on June 18, 2026 at 8:50 am

    Unless I’ve totally misunderstood your question, you don’t – and shouldn’t – use generic for this kind of problem. Using polymorphism and/or composition will be much more appropriate. For example, if you need to integrate a copy of the request in the response (hardly necessary but thinkable) then you can add a reference to a request object in your response class.

    Technically, this reference to a Request object could be defined using a type; however, you shouldn’t do that because it will always be a Request object (either a base class or a derived subclass) and not some kind of arbitrary class that could change with each instanciation of a response.

    You use generic when the type of each referenced object is totally different (for example, a List <String> or a List<Request>: there is no subclassing relationship between a String and a Request object) or when the use of polymorphism will not be sufficient because you are defining one or more new virtual functions in a subclass that are not present in the superclass.

    Building a Response to be based on a Request because a Request is processed to yield a Response is definitely not the way to go and your current Processor interface is a testimony to that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two different java projects (I'll call them project 1 and Project 2
I have made a quick fiddle: http://jsfiddle.net/tLLB4/ Ok, so the premise is, i'm hovering
I have a project that uses groovy and java code. The project is deployed
Using ASP.NET MVC4 I have created a DelegatingHandler in a WebAPI project. I use
I have a Maven project called Utils that i'm working on. I also have
I am knee deep in starting a new ASP.NET MVC project. Several tutorials have
So I have a VS 2010 solution containing one ASP.NET MVC 3 project and
I have two particular cases where I disagree with a coworker, whether constants should
On a flex project, I have a slider and text box on a form
I have a Setup deployment project in VS 2010. The project compiles perfectly with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.