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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:47:20+00:00 2026-05-23T02:47:20+00:00

It seems to me that there is a certain kind of method that we

  • 0

It seems to me that there is a certain kind of method that we should be able to declare. Something to the effect of ‘Constructor Method’ or ‘Constructor Helper’.

These would be methods that can only be called from constructors. There are a few reasons I can see for doing this:

  • First, I like my constructors to be clean. If I have to dump a lot of logic into a constructor, I would like to organize it. But then, the methods that I organize that logic into are probably not methods that I should ever call outside of a constructor. I would like to be able to declare constructor-only methods.

  • Secondly and similarly, readonly member variables can only be initialized inside a constructor. You can’t, for example, initialize a readonly variable in a method, even if you call that method from a constructor. I would like to be able to declare the method ‘constructor-only’, and then I would be able to initialize read only member variables in it.

  • Lastly, while I can see the argument that ‘if your constructors are complex enough to need to be reduced to multiple method calls, you’re doing too much in them‘, there is the case of having more than one constructor that might need the exact same logic as another. If I have three constructors that all need to initialize a readonly member variable, I should pull that initialization logic into a separate method. While I could set up such a method that returns the initialization value, as opposed to actually doing the initialization, I still would like to be able to declare such a method as ‘constructor-only’, since it probably shouldn’t be used anywhere else.

EDIT: Turning this into a question: are there problems that I’m not aware of with this idea, is it unnecessary, or could this actually be a useful feature?

Thanks

  • 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-23T02:47:20+00:00Added an answer on May 23, 2026 at 2:47 am

    Like you said in your last point. Having lot of logic in constructor is somehow wrong. At least for me. You should either do it somewhere else or don’t do it at all. Something like creating separate class that doest this and then pass this class as parameter into constuctor.

    And if your want to generalize constructor calls, you can chain different constructors, so when one is called, another is called too along with separate logic in the first one. Then some of those constructors can be private, so they cannot be called from outside.

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

Sidebar

Related Questions

It seems that there is a guidance that a model should not expose its
It seems that these two operators are pretty much the same - is there
It seems that there is a implementation of rope in my /usr/include/c++/4.5.1/ext/rope (and ropeimpl.h
It seems that there are several really fast prime factorization algorithms around (one that
After looking at RescueTime for windows/mac, it seems that there's a version for linux
How can I add an URL to the trusted site? It seems that there
I know, I know, its sounds silly, but it seems that there are no
Given that: There seems to be no easy way to get a list of
It seems to me that there are two scenarios in which to use JOINs:
I've found that there seems to be a problem using css transitions properties 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.