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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:38:25+00:00 2026-05-30T14:38:25+00:00

My problem is almost exactly the same as the problem posted here: Abstract class

  • 0

My problem is almost exactly the same as the problem posted here: Abstract class with final uninitialized field and I like the solution. However, my problem is a bit more complicated in that the abstract class has multiple final fields of varying types. For example, I have four int, two int[], and two double. What would be the best way to force the subclasses to initialize these variables?

Options I’ve considered:

  • Convert all fields to Strings and pass with a Map
  • Have a really long superclass constructor
  • Create a helper class that would act as a wrapper and encapsulate all the values, then pass an instance of this class to the base class

The first option is not very elegant, and seems a bit complicated, especially with arrays. The second option is very tedious, and the third option just seems like I’m overdoing it.

Is there a “correct” way of doing this? Or if not, which of the three options posed would be the most elegant?

  • 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-30T14:38:26+00:00Added an answer on May 30, 2026 at 2:38 pm

    I would go with the second, “Have a really long superclass constructor.” If we follow the approach detailed in the question you referenced, the superclass constructor is protected and not meant to be called by anything external to the class hierarchy or package. My feeling always is, once something is not exposed beyond that boundary – i.e., is not part of the “API” as it were – then it doesn’t matter what it looks like. Let it have eight different parameters of varying types, or even more. Yes, it’s visible from within the package, but it’s clear from the original solution that that constructor is not meant to be called by anything other than the subclasses. That’s another motivation for non-public visibility.

    Of course, your instincts for doing something cleaner are correct when it comes to public stuff. The fact that you asked this question at all shows you have the right instincts.

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

Sidebar

Related Questions

I'm running Zend_Search_Lucene, which is almost exactly the same as normal Lucene. I'm keeping
First, my teammate is successfully deploying on almost exactly the same setup and using
My problem is exactly same as described in following post but it hasn't been
I need a callback function that is almost exactly the same for a series
I have two insert statements, almost exactly the same, which run in two different
I've almost completely installed Boost, but I have a problem with how to set
I'm almost finished with my program, but I have one problem that I can't
Problem: I have an address field from an Access database which has been converted
Problem Language: C# 2.0 or later I would like to register context handlers to
I am not sure where exactly the problem is located but Capistrano takes about

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.