Reputation: 21
I am wondering what can be the potential benefit if I start to split the interface of my repository which has GET/CREATE/DELETE/UPDATE methods
and in one service I have like 10 entities which per each entity I have one repository, so in total I have 10 repository now,
What is the benefit of creating 4 interfaces per methods? which is going to be 40 interfaces in total, Isn't this over-engineering now?
Upvotes: 0
Views: 53
Reputation: 17144
For ten repositories used by only one service, the interface segregation principle implies at most ten interfaces. Because the service uses some subset of methods from each repository, providing an interface to each one exposes that subset which the service uses, and conversely hides that subset which the service does not.
Alternatively, the ISP is satisfied with a facade: one interface encompassing all repository methods used by that service. This approach has the advantage of hiding implementation details of the database schema: it isn't the service's concern that data happens to be organized into ten tables, or a hundred tables, or one single (NoSQL) table.
Separation by method, similar to CQRS, is orthogonal to the ISP. It does not necessarily change the repository interfaces and the ISP definitely does not imply CQRS or anything of the kind.
Upvotes: 0