I’m wondering what the perfect controller looks like. Currently I’m at this:

public class AppController extends Controller {
    public Result indexAction() {
        return success("Hello World");
    }
}
  • The controller must be called <Something>Controller so you know it’s a controller
  • The controller should, but doesn’t need to, extend a base controller to inherit functionality
  • An action must be called <something>Action so you know it’s an action
  • An action must return some kind of result object
  • An action doesn’t need parameters
  • The base controller should offer convenience methods for creating a result objects as clean as possible

This design doesn’t use any annotations because it doesn’t need to. At least yet. One alternative would be to call the method index() and annotate it with @Action but it wouldn’t do anything else. I think it’s important to indicate that the method is an action so the code is more readable and understandable at a glance. And suffixing “Action” or “Controller” does the job well in my opinion.