We have a large project that performs a lot of modelling and calculations. This code is being broken down into smaller, more manageable chunks, by shifting particular calculations into their own classes.
To try and keep the inputs and outputs constrained to the appropriate calculation method, two public nested property classes have been used (if property classes is the correct term for a class that only has properties).
The following is a made up example of how this is being approached:
public class SomeCalculation
{
public Result Calculate(Parameters p)
{
double foundValue = 0;
switch (p.ParamD)
{
case SomeEnum.Element1:
foundValue = p.ParamA + p.ParamB + p.ParamC;
break;
case SomeEnum.Element1:
foundValue = p.ParamA + p.ParamB - p.ParamC;
p.ParamC = 5;
break;
default:
p.ParamB = -2;
break;
}
return new Result()
{
FoundValue = foundValue,
NewParamB = p.ParamB,
NewParamC = p.ParamC
};
}
public class Parameters
{
public double ParamA { get; set; }
public double ParamB { get; set; }
public int ParamC { get; set; }
public SomeEnum ParamD { get; set; }
}
public class Result
{
public double FoundValue { get; set; }
public double NewParamB { get; set; }
public int NewParamC { get; set; }
}
}
This calculation would then be performed by instantiating and passing in the nested Parameters
class. The main advantages of this is that the Parameters
and Result
classes are kept with the Calculation
class, and the same nested classes names can be reused with other calculation classes.
I'm wondering if the above design pattern is a reasonable approach, even though the MSDN Nested Types page says to avoid publicly exposing nested types. Also, does it conform with standard practices (such as the SOLID principles) or will it have any limitations that could cause problems?
SomeCalculationParameters
andSomeCalculationResult
. No need to nest the classes then.