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

  • Home
  • SEARCH
  • 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 6068405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:42:41+00:00 2026-05-23T09:42:41+00:00

I am reimplementing a java program in D. I have used the factory pattern,

  • 0

I am reimplementing a java program in D. I have used the factory pattern,
that is, from the data “myclass” “5.3 ,6,8,10”, I use reflection to call the constructor

myclass(5.3 ,6,8,10);

How can I solve the same problem in D, that is, given a class name, and the parameters
the constructor takes (only primitives), create an instance of that class by calling the constructor in the parameters?

One obvious solution is the following: Make a huge switch/case statement,
with class names as cases, and make constructor take a double[] as argument.
This is ugly, since I need to add each new class to this list.

I might enforce each class to statically add themself to some global map,
mapping class name to constructor, somehow.

  • 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-23T09:42:42+00:00Added an answer on May 23, 2026 at 9:42 am

    You could have a list with helper objects. The helper objects (MiniFactory) basically have a test method and a factory method, so you can say:

    for (int i=0; i<max_classes; i++) {
        MiniFactory f = factoryList[i];
        if (f.typeIsMatching(inputString))
            return f.createObject(inputArgs);
    }
    

    With some luck you can use templates to define the MiniFactories.

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

Sidebar

Related Questions

I have an idea to write a note-taking app in Java that does some
I'm reimplementing a .Net API in Java and the API specifies a whole bunch
I have a list of integer ASCII values that I need to transform into
I'm re-implementing a old BBS MUD game in Java with permission from the original
I've recently (4 days) started to learn C++ coming from C / Java background.
Does anybody know of a good common frameworks for Java that has common but
I am currently working on reimplementing some algorithm written in Java in Python. One
Is there a way in Java to get a method to lock (mutex) the
When I developed a piece of (academic) software using Java, I was forced to
Is there a good reason why there is no Pair<L,R> in Java? What would

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.