您的设计存在缺陷。接口用于描述 API 的“公共契约”,因此您想要 (a) 私有 setter 和 (b) 受保护的实现是非常奇怪的。
接口级别的私有 setter 没有任何意义(如果您想要接口上只有 getter 的属性,请参阅 Mark Heaths 的回答)
受保护的实现也很奇怪,因为通过实现接口,属性无论如何都是公共的。
如果您需要更多帮助,您将必须提供有关您的设计的更多信息。
There is a flaw in your design. An interface is used to describe the 'public contract' of your API, so it's very strange that you want (a) a private setter and (b) a protected implementation.
The private setter at the interface level does not make any sense (see Mark Heaths answer if you want a property with only a getter on the interface)
The protected implementation is also weird, since by implementing the interface the property is public anyway.
You will have to provide more information about your design if you need more help.
发布评论
评论(2)
如果你想要私有集,只需在接口中指定一个get:
然后IWalker的实现者可以指定私有集:
If you want private set, just specify a get in the interface:
the implementer of IWalker can then specify private set:
您的设计存在缺陷。接口用于描述 API 的“公共契约”,因此您想要 (a) 私有 setter 和 (b) 受保护的实现是非常奇怪的。
如果您需要更多帮助,您将必须提供有关您的设计的更多信息。
There is a flaw in your design. An interface is used to describe the 'public contract' of your API, so it's very strange that you want (a) a private setter and (b) a protected implementation.
You will have to provide more information about your design if you need more help.