I have a drop down list contain "Add" and "Subtract". When user select either one, it will call a function Calculate()
private int Calculate(string sAction)
{
int iTotal = 0;
if(sAction == "Add")
{
iTotal = X + Y;
}
else if(sAction == "Subtract")
{
iTotal = X-Y;
} }
return iTotal;
}
I do not wish to hard coded it to compare the action. It seem like not fulfill Open Closed Principle. If I change the text in the drop down list, I need to change the function as well. May I know how I can improve this code? Thanks.