spring and interfaces

后端 未结 9 796
无人及你
无人及你 2020-12-08 14:45

I read all over the place about how Spring encourages you to use interfaces in your code. I don\'t see it. There is no notion of interface in your spring xml configuration.

9条回答
  •  再見小時候
    2020-12-08 15:31

    Writing separate interfaces adds complexity and boilerplate code that's normally unnecessary. It also makes debugging harder because when you click a method call in your IDE, it shows the interface instead of the implementation. Unless you're swapping implementations at runtime, there's no need to go down that path.

    Tools like Mockito make it very easy to test code using dependency injection without piling on interfaces.

提交回复
热议问题