General Object Design Question

Hello,

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.

Either of your options would work (adding from a user point of view or from a department point of view). Which makes more sense from your users’ perspective? Do that :slight_smile:

Also you can implement it in either controller, using class-based actions.

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.

I would have probably NOT created a separate class for managers and employees. Both would have been users. As for permissions control, I would have made manager, employee ‘roles’ in the RBAC system, where there would have been simple permissions as well like ‘change dept’, ‘assign as manager’ etc. These roles and permissions needs to be organized into a (rather simple and intuitive) RBAC tree and assigned to ‘users’ in your system.

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.