Reputation: 1043
Let's assume I have two service classes with the following methods:
Now, I am thinking about the aesthetics of theses classes. Imagine we want to implement a method which search for all user of a specific group. Which service class is responsible for such a method?
I mean, the return value is a user (or maybe a collection of users) but the parameter (which means the name of the group) is a group. So which service class is the better place to put this method in?
Upvotes: 1
Views: 63
Reputation: 5293
I would create another class called "Membership" and have the methods that search for users in groups or groups a particular user belongs to. I tend to err on the side of large number of small classes rather than small number of large classes.
Upvotes: 1
Reputation: 41767
I'd suggest the User Service, since you are requesting User entities. A service should shield consumers from implementation details (persistence mechanism etc), if the users were returned from the Group Service, it would require knowledge of how users are persisted.
Upvotes: 2
Reputation: 22565
Depends on the way of your thinking, If you want to search on users with specific group, So in fact you want do some search on users with specific criteria, so It's better to put it in user service, but if you want to get some property from group, it's better to put it in group service, You should show what's your class signature and their responsibility.
Upvotes: 1
Reputation: 36059
None of both. The method belongs in the class Group, which is returned by createGroup() and findGroup(). If only these two services are your options, though, go with the GroupService, because all arguments of GroupService get group names as arguments. It is more usual to vary the return type of methods than the argument.
Upvotes: 2