Should every single object have an interface and all objects loosely coupled?

后端 未结 7 1975
刺人心
刺人心 2020-12-24 05:23

From what I have read best practice is to have classes based on an interface and loosely couple the objects, in order to help code re-use and unit test.

Is this corr

相关标签:
7条回答
  • 2020-12-24 06:22

    It's useful for objects which really provide a service - authentication, storage etc. For simple types which don't have any further dependencies, and where there are never going to be any alternative implementations, I think it's okay to use the concrete types.

    If you go overboard with this kind of thing, you end up spending a lot of time mocking/stubbing everything in the world - which can often end up creating brittle tests.

    0 讨论(0)
提交回复
热议问题