objective-c – 数据封装……?

前端之家收集整理的这篇文章主要介绍了objective-c – 数据封装……?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_502_0@
有人能够向我解释一下Objective-C中的数据封装是什么吗?我被告知这是Objective-C的一个重要概念,但我不明白为什么……

向我解释好像我是5岁,然后好像我25岁……

谢谢你的时间,
〜丹尼尔

解决方法

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.

简单来说,向用户提供开发人员希望他们拥有的内容,并“保护”其他所有内容.开发人员可以在不需要重写代码的情况下更改内部任何内容.

如果开发人员不符合数据封装,那么每次发布新版本的库,代码片段或整个程序时,我们都需要重写代码.

猜你在找的C&C++相关文章