Best Design Pattern to Implement while Mapping Actions in MVC

Posted by FidEliO on Stack Overflow See other posts from Stack Overflow or by FidEliO
Published on 2012-12-15T14:50:52Z Indexed on 2012/12/15 17:03 UTC
Read the original article Hit count: 156

Filed under:
|
|

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;
             ...
    }
}

© Stack Overflow or respective owner

Related posts about java

Related posts about mvc