lundi 20 janvier 2020

How to deal with hierarchy problem of repositories pattern

Repository problem

I run into the problem. I have hierarchy-depended models in my Laravel application and I want to create repositories for all of them. The problem is that I need to have access to each repository in all other repositories. For example, I have the city model that aggregates people in the city and each person has his own set of items (aggregate items). I need to create the repository to create the city with the people and their items. To do that I need to have both city and item repository accessible in the create method of the city repository. I feel that it is not correct because in this example I have only 3 level hierarchy and the code will become messier if the hierarchy will increase.

The repository pattern schema can be found below

enter image description here

Aucun commentaire:

Enregistrer un commentaire