封装与抽象的真实世界示例 [英] encapsulation vs abstraction real world example

查看:71
本文介绍了封装与抽象的真实世界示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以封装为例,我可以想到用户与手机之间的交互.用户不需要知道手机的内部工作即可操作,因此这称为抽象.但是,封装在什么地方适合此示例?有人可以帮忙澄清一下吗?

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.

这篇关于封装与抽象的真实世界示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆