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

Ask A Question

Stats

  • Questions 140k
  • Answers 140k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer First of all I would like to point out that… May 12, 2026 at 7:56 am
  • Editorial Team
    Editorial Team added an answer If the method were defined directly in the controller, you'd… May 12, 2026 at 7:56 am
  • Editorial Team
    Editorial Team added an answer You're not gaining anything by actually having the using (and… May 12, 2026 at 7:56 am

Related Questions

I am particularly interested in Document Libraries, but in terms of general SharePoint lists,
Our company is facing some difficulties with our CMS web application. This application was
In designing any desktop applications, are there any general rules on how much memory
Binarization is the act of transforming colorful features of of an entity into vectors

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.