I am having trouble determining which design pattern I should use for this situation. I currently have a function which takes in a ENUM and uses variables from the class itself to do calculations. There are multiple equations / ways to get the calculated variable using different parameters. Currently, I have something which uses the parents class variables and takes in a enum determining which case it is. I want to split up the function and make it where a user has to pass variables to the function / split up the function and not rely on the parent class variables. For example:
public double CalculateVariable(double argument, VariableType varType)
{
var returnedVariable = 0.0;
switch (varType)
{
case 1:
//Use Equation 1 using variables (a,b,c,d) from parent class + argument
break;
case 2:
//Use Equation 2 using variables (a,c,f,g) from parent class + argument
break;
case 3:
//Use Equation 3 using variables (a,b,c,f) from parent class + argument
break;
}
return returnedVariable;
}
Is it proper to have some sort of Builder pattern to accomplish my goal of splitting up this function or is it better to have 5 different functions which says: CalculateVariableUsingXMethod, CalculateVariableUsingYMethod, CalculateVariableUsingZMethod. Which design pattern would I use?
Aucun commentaire:
Enregistrer un commentaire