Encapsulation is the mechanism that binds together code and the data it manipulates,
and keeps both safe from outside interference and misuse. In an object-oriented
language, code and data may be combined in such a way that a self-contained "black
box" is created. When code and data are linked together in this fashion, an object is
created. In other words, an object is the device that supports encapsulation.
Within an object, code, data, or both may be private to that object or public. Private
code or data is known to and accessible only by another part of the object. That is,
private code or data may not be accessed by a piece of the program that exists outside
the object. When code or data is public, other parts of your program may access it even
though it is defined within an object. Typically, the public parts of an object are used to
provide a controlled interface to the private elements of the object.
For all intents and purposes, an object is a variable of a user-defined type. It may
seem strange that an object that links both code and data can be thought of as a
variable. However, in object-oriented programming, this is precisely the case. Each
time you define a new type of object, you are creating a new data type. Each specific
instance of this data type is a compound variable.
and keeps both safe from outside interference and misuse. In an object-oriented
language, code and data may be combined in such a way that a self-contained "black
box" is created. When code and data are linked together in this fashion, an object is
created. In other words, an object is the device that supports encapsulation.
Within an object, code, data, or both may be private to that object or public. Private
code or data is known to and accessible only by another part of the object. That is,
private code or data may not be accessed by a piece of the program that exists outside
the object. When code or data is public, other parts of your program may access it even
though it is defined within an object. Typically, the public parts of an object are used to
provide a controlled interface to the private elements of the object.
For all intents and purposes, an object is a variable of a user-defined type. It may
seem strange that an object that links both code and data can be thought of as a
variable. However, in object-oriented programming, this is precisely the case. Each
time you define a new type of object, you are creating a new data type. Each specific
instance of this data type is a compound variable.