Why shouldn't C#(or .NET) allow us to put a static/shared method inside an interface?

后端 未结 7 1892
无人及你
无人及你 2020-12-11 04:24

Why shouldn\'t C#(or .NET) allow us to put a static/shared method inside an interface?

seemingly duplicate from here. but my idea is a bit different one, I just wan

7条回答
  •  猫巷女王i
    2020-12-11 04:52

    An interface is just that, an interface. It isn't meant to be used to describe behavior. When a class implements an interface, the class just says "I promise that I provide methods/events/etc with these signatures".

    What you want is an interface without the static method and an abstract base class that implements the interface and the static method. Then other classes can inherit from the base class and change the interface's method implementations. But even this is a questionable design.

提交回复
热议问题