General Object Design Question
Posted 15 March 2013 - 05:15 PM
Curious about how best to design a few classes. This is a simplified version, but just looking for concepts. Say I have 3 tables: Users, Departments, User_Departments.
A Manager is able to add an Employee (both Sub classes of User) to the User_department table. Where should this action reside?
Should this be in the Manager Controller (An extended UserController class), as it’s the job of the manager to add Users to this table? Or in the Department Controller, as the department controller should be responsible for actions relating to departments. Finally, should I create a User_Department Controller and store it in there.
While all 3 cases would work, I am looking for what’s the best practice, and for possible future changes, what would be easier.
Thanks in Advanced.
Posted 19 March 2013 - 01:01 AM
For example, create a CBA that takes two params: userId and departmentId.
Then create references to this class in both controllers using actions() array.
So basically you can have two URLs, (user/add_to_department and department/add_user) doing the same thing, without repeating the code.
I don't know if it's good or bad in your case, but anyway it's another option.
Posted 20 March 2013 - 02:44 AM
As for in which controller to place the action to handle assignment of users to departments? That's a matter of UI and is less important, probably. You can have it done from the department controller or from users controller. YYMV, according to you tendencies and requirements.