Best Design Pattern to Implement while Mapping Actions in MVC
- by FidEliO
What could be the best practices of writing the following case:
We have a controller which based on what paths users take, take different actions. For example:
if user chooses the path /path1/hello it will say hello. If a user chooses /path1/bye?name="Philipp" it will invoke sayGoodBye() and etc.
I have written a switch statement inside the controller which is simple, however IMO not efficient. What are the best way to implement this, considering that paths are generally String.
private void takeAction()
{
switch (path[1])
{
case "hello":
//sayHello();
break;
case "bye":
//sayBye();
break;
case "case3":
//Blah();
break;
...
}
}