how to choose the right action to implement the logic business
Suppose I have three entities.
- Department
- Task
- User
User can publish some Task belonging to his Departments. He can belong to more than one Department.
The relationships of the three entities are:
User---Task----many2many
User-Department --Many2many
Task--Department -- many2one
I use Hibernate and I set all of the associations as bidirectional.
Now I have some requirements:
- List all the tasks that belong to a specified user (the tasks this user published).
- List all the tasks that belong to user's department (if this user belong to dep1 and dep2, now I should list all the tasks of the dep1 and dep2).
- L开发者_如何学Cist all the tasks of a department.
- List all the tasks of all the departments.
These logic codes are not difficult, but where do I put these logics? to the UserAction or TaskAction or DepartmentAction?
If you are using the Rest plug-in, then it might make sense in general to have a DepartmentAction
, TaskAction
, and UserAction
, but you don't need to limit yourself to all-encompassing actions like those.
From your description, it sounds to me like the four requirements are all really one action that lists tasks by various criteria. Therefore, I would create a single action called ListTasksAction
. This action would take parameters to indicate which of the four criteria to limit on.
You could also create separate actions for the four requirements (perhaps with a shared interface or abstract class).
精彩评论