封装与抽象的真实世界示例
以封装为例,我可以想到用户与手机之间的交互.用户不需要知道手机的内部工作即可操作,因此这称为抽象.但是,封装在什么地方适合此示例?有人可以帮忙澄清一下吗?
For an example of encapsulation i can think of the interaction between a user and a mobile phone. The user does not need to know the internal working of the mobile phone to operate, so this is called abstraction. But where does encapsulation fit in to this example? Could someone please shed some light on this?
封装是一种实现 隐藏信息" ,因此,按照您的示例,您不需要知道手机的内部工作原理" 用它.您有一个界面来使用设备行为,而无需了解实现细节.
Encapsulation is a way to achieve "information hiding" so, following your example, you don't "need to know the internal working of the mobile phone to operate" with it. You have an interface to use the device behaviour without knowing implementation details.
抽象可以解释为对不同对象使用相同的界面的能力.可以存在相同接口的不同实现.详细信息通过封装隐藏.
Abstraction on the other side, can be explained as the capability to use the same interface for different objects. Different implementations of the same interface can exist. Details are hidden by encapsulation.