In a legacy project's service layer, there are tens of service classes and among them there is one service, UtilityService
using 2 other services:
class UtilityService{
private UserService userService;
private ContactService contactService;
//some methods using userService and contactService
}
This UtilityService
is used in the controller level classes with other services. Some controller classes have depednencies on both UtilityService
and UserService
since some methods in UserService
are needed in the controller
class but they are not delegated to UtilityService
:
class CustomerController {
private UserService userService;
private UtilityService utilityService;
public List<Customer> getAvailableCustomers() {
//here both userService and utilityService are in use
}
}
IMO, the dependencies on both UtilityService
and ContactService
in one controller class are subject to circular references => Question: how to improve the code structure so that circular references can be easily avoided?
UtilityService
(which really conveys no more information thanThingThing
), you should consider whether that class should exist at all. – Philip Kendall Feb 19 '24 at 18:29