liveBook · Manning

Interface Segregation Principle

As explained in Clean Applications with Hexagonal Architecture

The Interface Segregation Principle states that clients should not be forced to depend on interface operations they do not use.

A repository serving different consumers can accumulate methods for unrelated needs. Apply the Interface Segregation Principle by splitting it into focused interfaces, so each client depends only on the operations it uses. A single adapter can implement those interfaces. section 5.3.2

Repository contracts can separate writes such as save and delete, aggregate reads used before mutation, and DTO queries used to serve data. Command handlers use the first two; query handlers use DTO queries. section 5.3.2

Table 5.1 Read-side vs. write-side repository method conventions
Concern
Method prefix
Accepts
Returns
Used by
Persist state
save, delete
Domain entity
Either<Error, Void>
Command handlers
Load for mutation
read
Identifier
Either<Error, DomainEntity>
Command handlers
Retrieve for display
find
Identifier or criteria
Either<Error, DTO> or Either<Error, Collection<DTO>>
Query handlers

Compare repository method prefixes, inputs, return values, and the handlers that use them. section 5.3.2

How Clean Applications with Hexagonal Architecture covers it

How deep it goes
Defines read-side and write-side repository conventions, but leaves interface granularity to team judgment.
Examples
Uses ArticleRepository methods for saving, loading aggregates, and retrieving DTOs.
What you can do after
Apply it by splitting a growing repository into consumer-focused interfaces while retaining one adapter implementation.
How it connects
Links repository interfaces to output ports, command handlers, query handlers, and hexagonal architecture.

Also explained in

Compare how 4 books explain Interface Segregation Principle →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Clean Applications with Hexagonal Architecture. The section links point to the parts of the book it draws on.