intermediate

Interface Segregation Principle

Split broad contracts into role-specific capabilities so clients depend only on operations they actually need.

ISP: clients should not depend on methods they do not use—split fat interfaces into role-specific ones. A `Machine` that prints and scans becomes `Printer` and `Scanner` so a simple client does not implement no-op stubs.

Smaller interfaces simplify mocks, adapters, and evolution when only one role changes.

On interviews: refactor a bloated repository interface into read/write ports.

Common pitfalls: one interface per method extremes, breaking cohesion of truly atomic operations, and leaking persistence details into segregated names.

The trade-off is more interface types versus leaner dependents and tests.

Checklist:

  • Group methods by client role.
  • Remove forced empty implementations.
  • Keep atomic use-cases cohesive.