数据封装...? [英] Data encapsulation...?

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

问题描述

任何人都可以向我解释Objective-C中的数据封装是什么?有人告诉我,这是Objective-C的重要概念,但我不明白为什么...

Would anyone be able to explain to me what data encapsulation in Objective-C is? I've been told that this an important concept of Objective-C but I don't see why...

向我解释一下,好像我5岁,然后好像我25岁。...

Explain it to me as if I was 5 and then as if I was 25....

感谢您的时间,
〜Daniel

Thanks for your time, ~Daniel

推荐答案

来自 http:// mobile .tutsplus.com / tutorials / iphone / learn-objective-c-2 /


我们所说的数据封装是
通过方法包含(可以说)数据
的意思是要访问它,我们
需要使用方法。某些
用其他语言编程并且
尚未听说过数据封装
的人可能想知道为什么我们以这种方式使用
。答案是,通过
封装数据,
类的开发人员和类用户之间可以很好地缓冲
。因为
类方法管理和维护
类中的属性,所以它们
可以更轻松地维护数据
的完整性。
的另一个主要优点是,当开发人员分发他的
类时,使用它的人根本没有
担心
类的内部结构。开发人员可以更新
方法以使其更快或更有效,但此更新对于
类的用户而言是
透明的,因为他/她仍使用相同的方法
,而无需更改代码。

What we mean by data encapsulation is that data is contained (so to speak) by methods meaning to access it we need to use methods. Some of you who have programmed in other languages and havenʼt heard of data encapsulation may be wondering why we do things this way. The answer is that by encapsulating data, there is a nice cushion between the developer of a class and the user of a class. Because the class methods manage and maintains the attributes within the class, they can more easily maintain data integrity. Another major benefit is that when a developer distributes his class, the people using it donʼt have to worry about the internals of the class at all. A developer may update a method to make it faster or more efficient, but this update is transparent to the user of the class as he/she still uses the same method with no change to his/her code.

简单来说,就是为用户提供了开发人员所需的内容拥有并保护其他所有东西。开发人员可以在内部进行任何更改,而无需用户重写代码。

In simple terms, the user is provided with what the developer wanted them to have, and "protects" everything else. The developer can change anything internal without the user having to rewrite their code.

如果开发人员不遵守数据封装,则每次新的代码都需要重写代码。版本库,代码段或整个程序已发布。

If developers did not conform to data encapsulation, we would need to rewrite our code every time a new version of a library, code snippet, or an entire program was released.

这篇关于数据封装...?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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