Is it the best practice to extract an interface for every class?

后端 未结 13 2522
我在风中等你
我在风中等你 2020-12-04 17:43

I have seen code where every class has an interface that it implements.

Sometimes there is no common interface for them all.

They are just there and they are

13条回答
  •  遥遥无期
    2020-12-04 18:15

    The interfaces are good to have since you can mock the classes when (unit-) testing.

    I create interfaces for at least all classes that touches external resources (e.g. database, filesystem, webservice) and then write a mock or use a mocking framework to simulate the behavior.

提交回复
热议问题