When are interfaces needed?

前端 未结 15 1521
日久生厌
日久生厌 2020-12-13 00:56

(In the context of .NET for what its worth)

I tend to not use inheritance and rarely use interfaces. I came across someone who thinks interfaces are the best thing

15条回答
  •  一整个雨季
    2020-12-13 01:18

    Interfaces help you keep the dependencies on the abstractions.

    Code that uses the interface only depends on the interface, so you know that there are no artificial dependencies on the details. This gives you lots of freedom as far as changing code in the future, since you know exactly what should & shouldn't break when you 'fix' a bug or refactor.

    In my opinion, it's the essence of good code design.

提交回复
热议问题