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

后端 未结 13 2521
我在风中等你
我在风中等你 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:01

    If is a part of the Dependency Inversion principle. Basically code depends on the interfaces and not on the implementations.

    This allows you to easy swap the implementations in and out without affecting the calling classes. It allows for looser coupling which makes maintenance of the system much easier.

    As your system grows and gets more complex, this principle keeps making more and more sense!

提交回复
热议问题