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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T13:18:30+00:00 2026-05-11T13:18:30+00:00

In general, what is the maximum number of parameters a class constructor should accept?

  • 0

In general, what is the maximum number of parameters a class constructor should accept? I’m developing a class that requires a lot of initialization data (currently 10 parameters). However, a constructor with 10 parameters doesn’t feel right. That leads me to believe I should create a getter/setter for each piece of data. Unfortunately, the getter/setter pattern doesn’t force the user to enter the data and without it characterization of the object is incomplete and therefore useless. Thoughts?

  • 1 1 Answer
  • 1 View
  • 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. 2026-05-11T13:18:30+00:00Added an answer on May 11, 2026 at 1:18 pm

    With that many parameters, it’s time to consider the Builder pattern. Create a builder class which contains all of those getters and setters, with a build() method that returns an object of the class that you’re really trying to construct.

    Example:

    public class ReallyComplicatedClass {     private int int1;     private int int2;     private String str1;     private String str2;     // ... and so on     // Note that the constructor is private     private ReallyComplicatedClass(Builder builder) {         // set all those variables from the builder     }     public static class Builder {         private int int1;         private int int2;         private String str1;         private String str2;         // and so on          public Builder(/* required parameters here */) {             // set required parameters         }         public Builder int1(int newInt) {             int1 = newInt;             return this;         }         // ... setters for all optional parameters, all returning 'this'         public ReallyComplicatedClass build() {             return new ReallyComplicatedClass(this);         }     } } 

    And in your client code:

    ReallyComplicatedClass c = new ReallyComplicatedClass.Builder()         .int1(myInt1)         .str2(myStr2)         .build(); 

    See pages 7-9 of Effective Java Reloaded [pdf], Josh Bloch’s presentation at JavaOne 2007. (This is also item 2 in Effective Java 2nd Edition, but I don’t have it handy so I can’t quote from it.)

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

Sidebar

Related Questions

What general guidelines should I follow to degrade a JS-based web application gracefully? Are
Is their a general rule on what values to specify for the maximum depth
It's useful to me to have a data structure in Java that has all
I have a general doubt about how to design Android apps that use a
General I have two kind of users, and one field (cluster) that I want
In general, how do I recreate DB time out issue that are happening in
General Follow the same standards for all tests. Be clear about what each test
General tutorial or good resource on how to use threads in Python? When to
For general protocol message exchange, which can tolerate some packet loss. How much more
In general, what kinds of design decisions help an application scale well? (Note: Having

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.