vendredi 21 juin 2019

How to remove circular dependency between two classes in a same package?

We are doing some refactoring and we have hit the wall here. There are two service classes AService and BService doing different works have a circular dependency. Earlier they were in a different libraries so there was no circular dependency existed. But now after refactoring we have moved them into a single library into a single package. AService job is to persist some data into a NoSQL database for a separate use case. BService job is completely different than AService job. AService needs BService to GET some data. BService needs AService to write some data to NoSQL Database and reads back.

How to fix the circular dependency issue without making each of them depends on each other. Any design pattern for such issues?

class AService {
@Autowired
private BService bService;

}

class BService {
@Autowired
private AService aService;

}

Aucun commentaire:

Enregistrer un commentaire