实现一个接口,但改变一个成员为私有 [英] Implementing an Interface but changing a member to be private
问题描述
接口的所有成员默认都是公有的。但在我的界面的一些属性,我想用作某些子类实现我的接口的私有成员。这是东西,可以和在这里做还是我的路要走基础。我的工作在我的架构,这些天,所以我没有那么精通尚未使用多个接口。
All members of an Interface are public by default. But there are some properties in my interface that I want to be used as private members of some subclasses that implement my interface. Is this something that can and is done or am I way off basis here. I'm working on using more Interfaces in my architecture these days so I'm not that well versed yet.
推荐答案
点接口是它们提供了其它的目的可以使用与对象进行通信的合同。如果你改变它被声明为成员公共
到接口私人
然后你不履行合同 - 另一个对象可能需要读取该属性/调用该方法,你必须让他们。
The point of interfaces is that they provide a contract that other objects can use to communicate with your object. If you change a member which is declared as public
in an interface to private
then you're not fulfilling the contract - another object may need to read that property / call that method, and you must allow them to.
这是界面将永远不会有私人
成员的接口是两个对象之间的接口。内部私人
成员不只要你举起你的合同结束之至也。
An interface will never have private
members as an interface is for "interfacing" between two objects. Your internal private
members don't matter to it as long as you hold up your end of the contract.
这篇关于实现一个接口,但改变一个成员为私有的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!