Long-term switch statuses are often not approved. The solution is to use polymorphism. However, what if the thing I include is not a type code? What I would like to do is replace the switch statement with something like this ...
public void HandleString(string s = "Hello")
{
...
}
public void HandleString(string s = "Goodbye")
{
...
}
...
HandleString("Hello");
This will replace the following ...
string s = "Hello";
switch(s)
{
case "Hello":
...
break;
case "Goodbye":
...
break;
default;
break;
}
Any ideas? Theoretically, I think that you can completely abandon the "if / switch" statements and simply call methods that are automatically bound based on the value of the expression.
source
share