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 6550337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:12:13+00:00 2026-05-25T12:12:13+00:00

Im looking to implement a modular generic object factory in Java. My code will

  • 0

Im looking to implement a modular generic object factory in Java.

My code will comprise of three basic elements:

  1. A DataLoader, which will provide a generic Collection
  2. A factory, which, given an element T, returns an object of type U
  3. A class that ties the two together, and provides a Collection

The bit Im struggling with is that class 3 doesnt care about the type T. What does matter is that the factory and DataLoader use the same T – ie the raw data provided by the DataLoader should be usable by the builder to build the objects provided by the third class – but the third class doesnt care what that intermediate format is.

So how do I mandate that the generic type T is the same for 1 and 2 without that type being part of the specification of 3?

  • 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-05-25T12:12:14+00:00Added an answer on May 25, 2026 at 12:12 pm

    One option is to use a helper class with two type parameters to bind the data loader and factory together, and then wrap that helper in another class that doesn’t care about the original data loader’s type:

    public class DataLoader<T> {
        ...
    }
    
    public class Factory<T, U> {
        ...
    }
    
    public class Binder<T, U> {
        public Binder(DataLoader<T> dataLoader, Factory<T, U> factory) {
            ...
        }
    }
    
    public class ClassNumber3<U> {
        public ClassNumber3(Binder<?, U> binder) {
            ...
        }
    }
    

    You could even hide the existence of Binder from outside code by giving ClassNumber3 a generic constructor:

    public class ClassNumber3<U> {
        Binder<?, U> binder;
        public <T> ClassNumber3(DataLoader<T> dataLoader, Factory<T, U> factory) {
            binder = new Binder<T, U>(dataLoader, factory);
            ...
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am looking to implement a Java application that will compute a set of
I'm looking to implement something in Java along the lines of: class Foo{ private
Looking to implement a RIA (rich internet application) either as a java (JWS) application
I'm looking to implement a dictionary data structure in C which I want to
I'm looking to implement a simple timer mechanism in C++. The code should work
Looking to implement a Find Nearest process for a mobile web application that will
Looking to implement a RIA using AJAX with Java on the backend. I was
Im looking to implement a .net remoting system, where a number of clients will
Hi i am looking to implement my own custom file like object for an
I'm looking to implement a build system that will run unit tests and JSLint

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.