Why can't I have protected interface members?

后端 未结 13 1904
走了就别回头了
走了就别回头了 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:09

    An interface is just like the shape of a key.

    It's not the key.

    It's not the lock.

    It's just the slim contact point.

    For this reason all the members of the interface (that defines the shape of the key) must be public.

    For a key to open a lock it is important that they both share the same shape.

    By making the shape (the interface) public, you can let others create compatible locks or compatible keys.

    Otherwise, making it (the interface) internal you will not allow others to create compatible locks or compatible keys.

提交回复
热议问题