Let’s assume I have two service classes with the following methods:
- GroupService
- createGroup()
- deleteGroup()
- updateGroup()
- findGroup()
- UserService
- createUser()
- deleteUser()
- updateUser()
- findUser()
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?
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.