What makes you determine to create a new controller instead of adding more actions to an existing controller? Where do you draw the line and WHY?
What makes you determine to create a new controller instead of adding more actions
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
What certainly does not get into the picture is the number of actions¹ — at least in the sense that “oh, I ‘m over 50 actions in this controller, let’s start another one”.
The guideline² should be: controllers are a logical group for actions that operate on the same type of object (the same type of model might be a better definition). If it so happens that you have a model so rich in functionality that there are 30 separate actions that can be performed on it, go ahead and put them in the same controller.
On the other side of the coin: if you have simple models and you find yourself writing controllers with only a few actions each, that should be a reason to feel good about the maintainability of the application rather than a reason to worry.
Notes:
¹ Of course, a controller with that many actions is a red flag for possible code abuse so the number should come into consideration — just not as some kind of hard rule.
² And it’s really a guideline — the aim here is to build a maintainable system, not to follow some religious scripture.