Encapsulation C++


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 they represent a self-contained "black box".
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. 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. 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.
Previous
Next Post »