Is it a good practice to call methods from constructors?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
I assume you are talking about other private/public functions of the class which is being initialized.
Like anywhere else, I would say decomposing large complicated behavior into sub functions is good practice.
The obvious complication would be calling functions which rely on as-yet un-initialized content of the object.
Since the constructor and the other functions are in the class have the same visibility (from a code maintainability point of view) I don’t think it is unreasonable to say that it is ok to leverage other functions but necessary for the programmer to ensure that such circular dependencies are avoided (like virtual functions).