During object construction I should initialize several parameters. As an example
Vehicle (color)
I
Car (transmission type, air conditioning (boolean))
I
Cabriolet (roof (boolean))
I also need ability to Reload all parameters at any time (because my parameters are actually changable). I was thinking to create virtual ReloadParameters() method for each class which will call super and load this class parameters.
The problem is that I also need to load all parameters during construction and I don’t want to call virtual method from constructor because this is bad practice.
What would you suggest?
To avoid calling a virtual method in the constructor, make a non-virtual private method, and call that from both the constructor and the virtual method:
If your base class has no parameterless constructor, or if it has more than one constructor, you’ll need to specify which base constructor to call, of course, like this: