1) Is it wrong if I insert a UserService in my ProductService class?
There is nothing wrong with the following reservations:
- Keep in mind that you can potentially move in the direction of one class doing too much (here ProductService)
- Be careful that you do not introduce circular dependencies (you should not have a UserService also dependent on ProductService)
- Limit hard communication by connecting your dependency to an interface, not to a specific class (here you use AutService UserService instead of UserServiceImpl, which is good).
2) Is there a name for this type of class (which introduces both UserService and ProductService)?
Yes, as already mentioned, you could call this class a Mediator, since the "Mediator" seems to describe it.
You can have both low-level services and high-level services, and low-level (ProductService, UserService) are embedded in high-level (say, PurchaseOrderService or PurchaseOrderMediator). Alternatively, for this particular case, you might think that the product service is the only high-level service that depends on the UserService. At this point, its more about which design is more cohesive in the context of your business logic and your application.
source share