Should one interface inherit another interface

后端 未结 6 1890
抹茶落季
抹茶落季 2021-01-30 12:17

I can\'t seem to find an answer on this and just want to make sure it\'s an ok coding standard. I have interface A that is used by many different classes and don\'

6条回答
  •  无人及你
    2021-01-30 13:13

    Technically speaking, interfaces don't inherit from each other. What really happens when you create an IFoo that inherits from IBar, you're saying that any class that implements IFoo must also implement IBar.

    interface IBar
    {
        void DoBar();
    }
    
    interface IFoo : IBar
    {
        void DoFoo();
    }
    

    In this example, the IFoo interface does not have a DoBar() method. Most of the time the distinction doesn't matter, but it can bite you when using reflection on an interface rather than a class.

提交回复
热议问题