Specify Generics in interface extends

Should I specify the concrete type for generic types when extending an interface with another interface? What I mean is, if I have an interface: public interface Repo{ Collection search(String params); T get(String id); } and then a whole bunch specific Repositories, like **ClientRepo**, **CustomerRepo**, etc... is it reasonable to specify the type **T** when extending this interface, e.g.: public interface ClientRepo extends Repo{ } public interface CustomerRepo extends Repo{ } where Client and Customer are just some classes. Did anyone have a similar problem? I mean I could do: public interface ClientRepo extends Repo{ } **Addendum**: Perhaps I should make my intent for having specific Repos (e.g. ClientRepo) more clear. There is another interface called **RepoFactory** that returns appropriate Repo to the client, e.g.: public interface RepoFactory{ ClientRepo createClientRepo(); CustomerRepo createCustomerRepo(); } This factory is implemented by **implementors** which in turn, provide the appropriate implementations of the concrete Repos. In fact from the above you could say that the interface **Repo** is not used by the client of the api. Confusing enough I hope!!! Sorry :(

以上就是Specify Generics in interface extends的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准