Would it be a good design to have multiple repositories for one entity?

  softwareengineering

I am working on a project. I have designed the codebase all the way from the scratch. Basic thing is the project is divided in individual modules. The modules represent one complete part of a business process. For example, AnalyticsModule deals with the analytics stuff of the project, PlatformModule deals with the other processing done on the platforms.

There are repositories in the project which corresponds to their entities. You write fetching/creating/updating/deleting logic in the repositories and those repositories return the entity instance. You don’t write any logic in entities, just the table column definitions and relationships.

Now there is a PlatformEntity and corresponding PlatformRepository in PlatformModule. While working in the AnalyticsModule, I need some logic to count the number of platforms and provide the number of times a platform has been visited. This can be done in the PlatformRepository as I will start fetching the platforms and count their visits, but I wanna write this logic in AnalyticsModule as this method better belongs to the analytics part of the project.

Now, I have already added the support of multiple repositories per entity from the very beginning, but I am wondering whether this approach of having multiple repositories would be good or bad. Having two repositories for PlatformEntity (one in PlatformModule and the other one in AnalyticsModule) solves my problem though.

New contributor

Muhammad Waqar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

1

LEAVE A COMMENT