What is the best universal approach (speed and handling) for managing constant data that is dependant on one or several conditional variables (int, float, string, ...)?
Basic examples:
Car CreateCar(int brand)
{
//...
float colourValue = GetRandomFloat(0F, 1F);
car.Coulor = GetCarCoulor(brand, colourValue);
//...
}
//-------------
//Example for data functions:
//-------------
string GetCarCoulor(int brand, float colourValue)
{
if (brand == 0)
{
if (colourValue < 0.3)
return "red";
else if (colourValue < 0.7)
return "green";
else
return "blue";
}
else if (brand == 1)
{
if (colourValue < 0.2)
return "red";
else
return "blue";
}
//...
return "default";
}
float GetCarSpeed(int brand, int carModel, int gear, bool returnMin)
{
if (brand == 0)
{
if (carModel == 0)
{
if (gear == 1)
{
if (returnMin)
return 1F;
else
return 15F;
}
else if (gear == 2)
{
if (returnMin)
return 15F;
else
return 40F;
}
}
//...
}
else if (brand == 1)
{
//...
}
//...
return 0F;
}
Functions with if-else constructs are obviously the most basic form that work for most data but doesn't necessarily look/handle and perform very well with bigger data sets.
Otherwise there are Dictionary<T1,T2>
and switch
constructs that come to mind, but these don't work that well with multiple or some types of input variables.
So are there any other kinds of constructs/approaches to look up constant data or some kind of best practice rules for that?
I also read of using XML files for data storage. Is this generally advisable for these kind of data, or is it slower or adds too much complexity? Advantages/disadvantages?
EDIT: Extended example to show what kind of data functions I had in mind.