Slicing Port Interfaces
Explore how to slice port interfaces when implementing persistence adapters using the Interface Segregation Principle. Understand why broad repository interfaces create unnecessary dependencies, complicate testing, and hinder maintainability. Learn to design narrow, cohesive interfaces that reduce mock complexity and improve code clarity, making your software architecture more flexible and easier to manage.
We'll cover the following...
One question that comes to mind when implementing services is how to slice the port interfaces that define the database operations available to the application core.
It’s common practice to create a single repository interface that provides all database operations for a certain entity as shown in the figure below.
Broad ports
Each service that relies on database operations will then have a dependency to this single “broad” port interface, even if it uses only a single method ...