向我解释好像我是5岁,然后好像我25岁……
谢谢你的时间,
〜丹尼尔
解决方法
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.
简单来说,向用户提供开发人员希望他们拥有的内容,并“保护”其他所有内容.开发人员可以在不需要重写代码的情况下更改内部任何内容.