c ++中的数据隐藏和抽象之间有什么区别?我们如何通过示例来区分它们? [英] What is the difference between data hiding and abstraction in c++ ? How can we differentiate both of them with examples ?

查看:102
本文介绍了c ++中的数据隐藏和抽象之间有什么区别?我们如何通过示例来区分它们?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

c ++中的数据隐藏和抽象之间有什么区别?我们如何用示例来区分它们呢?

What is the difference between data hiding and abstraction in c++ ? How can we differentiate both of them with examples ?

推荐答案

绝对不正确的问题.苹果和苹果有什么区别?

只是一个提示.抽象是哲学范畴,在编程中非常普遍.当您简单地编写一个函数时,这就是抽象.如果可以从不同地方调用if代码.如果向函数添加参数,则这是抽象的.以前,您具有硬编码的值,现在将其提升为参数,因此可以使用不同的值来调用函数.您可以通过将其提升为参数来抽象出具体的价值.一个好的开发人员编写的几乎所有内容都是抽象.

数据隐藏是更专业的类别.它是OOP不可或缺的一部分,而不仅仅是OOP.例如,局部变量对外部上下文是隐藏的.

-SA
Absolutely incorrect question. What is the difference between apple and Apple?

Just a hint. Abstraction is philosophical category, very universal in programming. When you simply write a function, this is abstraction. If can be called from different places if code. If you add a parameter to a function, this is abstraction. Before, you have a hard-coded value, now you promoted it to a parameter, so a function can be called with different value. You abstracted out of concrete value by promoting it to a parameter. Almost everything a good developers writes is abstraction.

Data hiding is more specialized category. It is integral part of OOP, but not just OOP. For example, local variables are hidden from outer context.

—SA


抽象,封装和信息隐藏之间的区别 [
Google?[^]

Difference between Abstraction, Encapsulation and Information Hiding[^]


以上所有答案都是正确的,我只是想多说一点,抽象是隐藏复杂性,而封装是隐藏数据,尽管您不能很容易地将两者分开,但是封装更像是安全性,例如私有成员被隐藏而公开向所有人展示.另一方面,抽象意味着无需显示执行特定操作所执行的步骤的复杂程度.

问候
Above all answers are correct, I just wanted to a little more, Abstraction is hiding complexity and Encapsulation is hiding data, though you cannot separate the two very easily, but Encapsulation is more about security,like private members are hidden and public are shown to all. On other hand Abstraction means no need to show how complicated steps you have performed to do particular operation.

Regards


这篇关于c ++中的数据隐藏和抽象之间有什么区别?我们如何通过示例来区分它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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