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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:58:04+00:00 2026-05-10T19:58:04+00:00

Is it a good idea (from a design POV) to nest constructor calls for

  • 0

Is it a good idea (from a design POV) to nest constructor calls for overloaded New or Factory style methods? This is mostly for simple constructors, where each overload builds on the previous one.

MyClass( arg1 ) {      _arg1 = arg1;      _otherField = true;      _color='Blue'  } MyClass( arg1, arg2) : this(arg1) {      _arg2 = arg2   } MyClass( arg1, arg2, arg3) : this(arg1, ar2) {      _arg3 = arg3;  } 

Or with factory methods:

static NewInstance(arg1 ) {     _arg1 = arg1;        } static NewInstance(arg1, arg2) {    f = NewInstance(arg1);    f._arg2 = arg2; } //... and so on 

I can see a few drawbacks on both sides

  • Nesting hides what the constructor is doing
  • Not nesting duplicates all the functionality

So, is doing this a good idea, or does it set me up for something I’m just not seeing as a problem. For some reason I feel uneasy doing it, mostly because it divides up the responsibility for initializing.

Edit: @Jon Skeet: I see now why this was bothering me so much. I was doing it backwards! I wrote the whole thing and didn’t even notice, it just smelled. Most other cases I have (that I wrote), do it the way you recommend, but this certainly isn’t the only one that I have done like this. I do notice that the more complicated ones I did properly, but the simple ones I seem to have gone sloppy. I love micro edits. I also like acronymns!

  • 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. 2026-05-10T19:58:04+00:00Added an answer on May 10, 2026 at 7:58 pm

    I think it’s reasonable to chain constructors together, but I do it the other way – the version with fewer parameters calls the version with more parameters. That way it makes it very clear what’s happening, and all the real ‘logic’ (beyond the default values) is in a single place. For example:

    public Foo(int x, int y) {     this.x = x;     this.y = y;     precomputedValue = x * y; }  private static int DefaultY {     get { return DateTime.Now.Minute; } }  public Foo(int x) : this(x, DefaultY) { }  public Foo() : this(1, DefaultY) { } 

    Note that if you have lots of constructor overloads, you may wish to move to static factory methods instead – that usually makes the code clearer, as well as allowing multiple methods to take the same set of parameters, e.g.

    public static XmlDocument FromText(string xml)  public static XmlDocument FromFile(string filename) 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

From a design and loose coupling standpoint. Is it a good idea to have
When is it a good idea to use PHP_EOL ? I sometimes see this
I've read that Strategy objects often make good flyweights (from Design Patterns Elements of
Does this facade code look like a good idea, or is there anything inherently
After reading this question I just wondered whether it would be a good idea
I'm quite new to Android development. When is it a good idea to create
Is it a good idea to use while loop instead of a cursor? What
Is it a good idea to store my SQL queries in a global resource
Is it a good idea for me to use Qt Jambi in Java as
When is a good idea to save information in a XML file and when

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.