A single interface with operations a client never uses can make an application more complex. Interface segregation favors focused contracts, so each client can choose the operations it needs. Spring Data applies this idea through repository interfaces. section 14.2
Choose a Spring Data contract to match the repository’s needs:
- Use CrudRepository when CRUD operations are enough; it avoids adding paging and sorting operations. section 14.2
- Use PagingAndSortingRepository when the application also needs paging and sorting. section 14.2
- Choose a technology-specific contract, such as JpaRepository or MongoRepository, for operations tied to that persistence technology. section 14.2
Figure 14.7 To create a Spring Data repository, you define an interface that extends one of the Spring Data contracts. For example, if your app only needs CRUD operations, the interface you define as a repository should extend the CrudRepository interface. The app adds a bean that implements the contract you define to the Spring context, so any other app components that need to use it can simply inject it from the context.

See how a repository interface can extend CrudRepository when only CRUD operations are needed. section 14.2



