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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:45:56+00:00 2026-05-31T19:45:56+00:00

I am not sure if a similar question has been asked before, searched for

  • 0

I am not sure if a similar question has been asked before, searched for it, but did not get any helpful answers.

As the question suggests, what is better, having an overloaded constructor or having multiple setter functions?

Scenario:

public class Something {

    private int a;
    private int b; 

    public Something(int a, int b) {
        this.a = a;
        this.b = b;
    }
    ... // Do Something
}

Now, my basic requirement was for to have two parameters only. Now tomorrow, the requirement is changed and I am asked to add a new parameter, c and then the next day d, and given a statement saying we can have more fields.

I already have dependency for this constructor in multiple projects. Now, back to my question

  • Is it advisable to keep adding the new fields to the already overloaded constructor?
  • Create a new overloaded constructor every time I need to add a new field so that I don’t break dependent code?
  • Or simply use the default empty default constructor and use setters only (messing up my immutability, which is not of high concern)

What is the advice that you can give me?

  • 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-31T19:45:58+00:00Added an answer on May 31, 2026 at 7:45 pm

    The most pleasant way to do this is to continue adding the fields to your constructor — having setters means you can’t have immutable objects, and immutable objects are always nice — but possibly to investigate the builder pattern, which can help you limit yourself to just one constructor that gets called and “filled in” by the builder object.

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

Sidebar

Related Questions

I'm not sure is similar question has been asked before (I couldn't find any),
I know similar questions have been asked, but I'm not sure about the answers
So, if this question has been asked before, I'm sorry. I'm not exactly sure
I'm sure some variation of this question has been asked before but all other,
I'm sure this has been asked before, but my perusal of the search hits
I know a similar question has been answered before here , but I just
Sorry if this has been asked before - there's a question with a similar
I am not sure if this question has been asked here or not. I
I know this question has been handeled in similar situations, regarding ASP.Net, before. But
I'm trying to implement something similar to what http://www.ancestry.com has, but I'm not sure

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.