了解封装和抽象的简单方法 [英] Simple way to understand Encapsulation and Abstraction

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

问题描述

学习OOP概念,尤其是对深入理解抽象和封装感兴趣的人.

Learning OOP concepts especially interested to understand Abstraction and Encapsulation in depth.

已经检查了以下内容

抽象VS信息隐藏VS封装

抽象与封装之间的区别?

我发现很难用一个真实而简单的示例类/代码片段来理解这些概念.

I found very hard to understand those concepts with out a real and simple example class/code snippet.

我的一位同事说抽象只不过是创建抽象 类和使用范围保护其成员变量的普通类是 称为封装.

One of my colleagues said abstraction is nothing but creating abstract class and normal class that protects its member variable with scope is called Encapsulation.

有没有一种简单的方法可以理解并帮助他人了解他们的确切身份,而不是重复以下内容?

Is there a simple way I can understand and help others to understand what exactly they are, rather than repeating the below?

抽象和封装是互补的概念:抽象 专注于对象的可观察行为...封装 着重于引起这种行为的实现... 封装通常是通过信息隐藏来实现的, 是隐藏不存在的所有对象机密的过程 有助于其基本特征.

Abstraction and encapsulation are complementary concepts: abstraction focuses on the observable behavior of an object... encapsulation focuses upon the implementation that gives rise to this behavior... encapsulation is most often achieved through information hiding, which is the process of hiding all of the secrets of object that do not contribute to its essential characteristics.

推荐答案

抽象是一个仅向用户显示相关"数据和隐藏"对象不必要细节的过程.考虑到您的手机,您只需要知道要发送消息或拨打电话时要按下的按钮,按下按钮时会发生什么情况,消息的发送方式,呼叫的连接方式都与抽象无关.用户.

Abstraction is a process where you show only "relevant" data and "hide" unnecessary details of an object from the user. Consider your mobile phone, you just need to know what buttons are to be pressed to send a message or make a call, What happens when you press a button, how your messages are sent, how your calls are connected is all abstracted away from the user.

封装是将数据和功能组合到称为类的单个单元中的过程.在封装中,不直接访问数据.可通过类中提供的功能对其进行访问.用简单的话来说,该类的属性将保持私有状态,并提供公共的getter和setter方法来操纵这些属性.因此,封装使隐藏数据的概念成为可能.

Encapsulation is the process of combining data and functions into a single unit called class. In Encapsulation, the data is not accessed directly; it is accessed through the functions present inside the class. In simpler words, attributes of the class are kept private and public getter and setter methods are provided to manipulate these attributes. Thus, encapsulation makes the concept of data hiding possible.

这篇关于了解封装和抽象的简单方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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