Is there a reason you can not define the access modifier on a method or in an interface?

后端 未结 5 2002
悲哀的现实
悲哀的现实 2020-12-21 00:23

The responsibility of the visibility of a method is relegated to the class that implements the interface.

public interface IMyInterface
{
  bool GetMyInfo(st         


        
5条回答
  •  星月不相逢
    2020-12-21 00:58

    A private definition in the interface would:

    1. provide no benefit to the user of the interface (it is private after all)
    2. constrain the implementing class to have to implement the method or property
    3. muddy the conceptual nature of the interface with implementational detail
    4. be like an abstract class with a private method (which is not allowed)

提交回复
热议问题