Definition for the concepts of data hiding:
Hiding representation details using objects can happen using the
Abstraction concept in Object oriented programming language.
Abstraction can be achieved using the concepts encapsulation and
inheritance concepts.
Abstraction: It is a concept in which only the
essential details are represented and non-essential details are
hidden.
Encapsulation: In this concept the data is
wrapped just like in a capsule and is hidden from all the other
classes. This data can only be accessed by the methods that are
defined in the same class.
Inheritance: In this a parent child
relationship is being set between different objects. The child
object acquires the properties of the parent object and can use the
data and methods of the parent object all with its own data and
methods.
Two advantages of hiding representation details using
objects are:
- It reduces the complexity of the data that is used to represent
the different objects. As it reduces complexity, it becomes easy to
reuse the code, making it more efficient. Hiding helps to define
the interfaces between different objects making it more easy to
understand and readable and legible. It is easy to modify the data
in the class as it does not affect the other objects as the objects
are decoupled from each other. It helps in reducing the data
redundancy as the data that is required in more than one object can
be written once in an object and then it can be inherited by other
objects as well by creating the parent-child relationship.
- As the data is hidden from the outside environment therefore it
provides security to the data of that particular class as no other
class is able to access that data until and unless the public
access is provided to that data. Also as they are bundled in the
same unit or the capsule called class, therefore it becomes easy to
manage them and maintain them. The objects can be written once and
can be used again and again on different platforms increasing their
reusability.