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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:32:01+00:00 2026-05-25T22:32:01+00:00

I have a set of java subclasses which all extend the same superclass. They

  • 0

I have a set of java subclasses which all extend the same superclass. They contain exactly the same methods and make the same computations on input data of different type. That means that one is responsible to deal with int, another with double, another with int Array, List etc. Objects of each type should be created at runtime of the program according to the input data each time.

What is the best way to specify what kind of object (of the referred subclasses) will be created each time while the program is running? It seems not possible to use something like type checking since the data could be of different type (class).

Do I need a separate class that is responsible exclusively for this task, something that serves as an object generator? If so, is there a hint available about what would be the form and functionality of such a class?

Thank you.

  • 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-25T22:32:02+00:00Added an answer on May 25, 2026 at 10:32 pm

    I’m not sure I understood your question correctly as it’s not very clear, some examples of your class and of what you trying to accomplish would help.

    Anyway, what I got from it is that you should check the Visitor pattern.
    http://en.wikipedia.org/wiki/Visitor_pattern

    In simpler words, I would separate the actions you want to make with each type, and have one class for each one of these (instead of having all these as methods in all your subclasses).

    And you would do something like that:

    yourSubclass.accept(yourAction)
    

    A visit method would be defined on the Visitor interface, once for each type of Subclass you have. And each of your action class would have to implement what to do for each one of these. And the accept method, in your superclass, would just call visit from the action.

    If this is not what you asked, sorry 🙂

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

Sidebar

Related Questions

I have some classes that all implement the same Java interface, which essentially allows
I have set my java min/max heap size to be the same as outlined
I have a Java method in which I'm summing a set of numbers. However,
In a Java program, I have multiple subclasses inheriting from a parent (which is
I have a CVS repository in which I have a set of Eclipse Java
I have a set of Java 5 source files with old-style Doclet tags, comments
I have a set of source folders. I use a Java class to build
I have a Java application set up as a service to do data-mining against
I have a java.util.Set<City> cities and I need to add cities to this set
I have a long set of comparisons to do in Java, and I'd like

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.