Why can't I have protected interface members?

后端 未结 13 1897
走了就别回头了
走了就别回头了 2020-11-29 19:58

What is the argument against declaring protected-access members on interfaces? This, for example, is invalid:

public interface IOrange
{
    public OrangePee         


        
13条回答
  •  既然无缘
    2020-11-29 20:11

    An interface is a contract that promises certain functionality to clients. In other words, the purpose of an interface is to be able to cast a type into it and pass it around like that to code that needs the features guaranteed by that interface. Since client code of a type cannot access protected members of that type, it makes no sense to declare protected items in an interface.

提交回复
热议问题