When to use Single method Interfaces in Java

前端 未结 5 776
无人及你
无人及你 2021-02-01 04:50

I have seen in many libraries like Spring which use a lot of interfaces with single methods in them like BeanNameAware, etc.

5条回答
  •  春和景丽
    2021-02-01 05:32

    You create interfaces not according to the number of methods in it but to define behaviour expected by components of your systems to deliver a single responsibility to their neighbors. If you follow this simple principle/rule, you might or might not end up with single method interfaces, depending on the responsibility you are defining. I like to keep tests stupid simple and the application very flexible so I usually have many of those

提交回复
热议问题