let’s say I have a class that does some calculations. This set of calculations requires as an input a set of parameters.
public class Calculator
{
private CalculatorConfig _config;
public Calculator(CalculatorConfig config)
{
_config = config;
}
public Result Calculate(object obj){}
}
My CalculatorConfig class is very simple :
public class CalculatorConfig
{
public double param1;
public double param2;
...
}
and I initialize it very simply
var config = new CalculatorConfig();
config.param1 = val;
....
var calculator = new Calculator(config);
The dilema I have is that user of this class may forget to initialize some of the fields which may lead to weird behaviour.
Solution that may make a sense would be to convert fields into properties and for each private field have an extra boolean that would hold the information whether the field was initialized.
I can also create a megaconstructor, that would have all the fields as arguments.
What approach would you choose in this case?
Thanks
I will use another approach.
In the Check method verify each parameter and throw a custom
exception is something is wrong