Ask a Teacher



differentiate data hiding and encapsulation

Data encapsulation and data hiding fall under object oriented programming and can be used in different programming languages like C, C++, and others. The two are considered as the two main concepts of the object oriented programming system. Data encapsulation and data hiding involve objects (classified as values, data, structures, or functions), classes (collection of data and methods), the computer code, and methods.

Data encapsulation is the process of combining and assembling elements in order to create a new entity and the wrapping of private data into a class. The encapsulation involves implementation concerning the data and the method. Data with internal methods are secured into a capsule while the methods are used to access the data inside it. In this manner, the assembly and grouping of all data and requirements inside a capsule makes it independent for an object to function together.

The encapsulation also involves how the class is hidden from users and how the process can be reversed by unlocking the capsule using methods. In data encapsulation, the capsule and the object inside it can be classified as either private or public unless specified or programmed by the programmer.

On the other hand, data hiding is the process of hiding the details of an object or function. It is also a potent technique in programming that results in data security and less data complexity. One of the manifestations of data hiding is that it is used as a method to hide information inside a computer code after the code is broken down and hidden from the object. All objects in the state of data hiding are in isolated units which is the main concept of object-oriented programming.

The data inside is classified as private or non-accessible from other objects, classes, and API's in the system. The data appear as invisible from outsiders whether objects, other classes, or users. The relationship between data encapsulation and data hiding is that the data encapsulation is one of the chief mechanisms of data hiding. Data hiding works by nesting the data or arranging the data into capsules.



comments powered by Disqus