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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:04:20+00:00 2026-06-12T14:04:20+00:00

I have two options. Either make a class that accepts a lot arguments in

  • 0

I have two options. Either make a class that accepts a lot arguments in its constructors, or create a lot of setter methods and an init method. I’m not sure which is preferred option, should some arguments be accepted in constructors, while others could be manually set via setter? Or am I over-thinking this?

This is a relevant question, also by me: Conflicts between member names and constructor argument names.

  • 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-06-12T14:04:21+00:00Added an answer on June 12, 2026 at 2:04 pm

    If after you create an object you have to call set or init to actually use it… well, that’s just an awful design.

    If the object is usable without some of the members initialized the way you want them to be, you can set them later on.

    The golden rule here is – if you create an object, you should be able to use it without doing any other sort of initialization.

    Expanding on the answer:

    Say you have a shape with 10 sides, 10 corners, a color and a name, that can be connected to a different shape. The constructor should look like:

     MyShape(Point c1, Point c2,...., Point c10, Color c, Name n)
    

    As you can see, I’ve omitted the connected shape because it can sensibly be set to NULL if the current object is not connected. However, in the absence of any of the other parameters, the object isn’t valid, so they should be set in the constructor.

    A possible overload (alternitively a default argument) can be:

     MyShape(Point c1, Point c2,...., Point c10, Color c, Name n, 
                                          MyShape* connectedShape /*=NULL*/)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two models like this: class OptionsAndFeatures(models.Model): options = models.TextField(blank=True, null=True) entertainment =
I want to parse a large XML file and I have two options: Perl
Hy, I have two options to choose from: Client side(with FLASH or Javascript): pro:
I have a ADO.NET/TSQL performance question. We have two options in our application: 1)
I am implementing slideshow. I have two options for paging between images: 1) to
I need to write data into drive. I have two options: write raw sectors.(_write(handle,
I have two overlay options in my map: a MKCircleOverlay and a MKPolygonOverlay.The first
I have two drop down menus where the options are not get from the
At the moment I have two tables, products and options . Products contains id
I have a page with an image, and two options: Show image full browser

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.