Spring数据自定义存储库和接口隔离原则

Spring data custom repositories and interface segregation principle

我正在开发我自己的存储库模型,我有这个:

我遵循接口隔离原则。我有一个 ReadRepository 只定义读取操作,PaginationRepository 在 ReadRepository 方法上添加分页,CrudRepository 包含所有 CRUD 操作。最后,我有具有 PaginationRepository 和 CrudRepository 行为的 BaseRepository。正如您在图片中看到的,BaseRepository 通过它的两个父类从 ReadRepository 扩展了两次。这个模型让我可以灵活地创建特定的实体存储库(只读、只读 + 分页、crud 操作或 crud 操作 + 分页)但是,传递继承是一种不好的做法吗?

深度继承结构只有在用于继承实现时才被认为是一个问题。对于接口,我看到的唯一潜在问题是您最终可能会使用来自不同接口的不同方法,当两个接口都实现时,这些方法就变成了一个。但由于所有接口都在您的控制之下,所以这应该不是问题。