What is Data hiding?
Data hiding is a software development technique specifically used in object-oriented programming (OOP) to hide internal object details (data members). Data hiding ensures exclusive data access to class members and protects object integrity by preventing unintended or intended changes. Data hiding also reduces system complexity for increased robustness by limiting interdependencies between software components.Â Data hiding is an extreme version of encapsulation where you not only don’t want the user to access the data members, but you also don’t even want them to be able to see what they are.
- Outside person can’t access our internal data directly or our internal data should not go out directly this OOP feature is nothing but data hiding.
- By declaring Data Member(Variable) as Private we can achieve data hiding.
- Data hiding is also known as Information hiding.
- The main advantage of data-hiding is security.
- Note:- It is highly recommended to declare data member(variable) as private.
- It just provides a way to protect your data from the outside world. What it means is, let’s say if I made my instance variable public, then anyone can change its state. But if we make our instance variable private/protected then actually we are restricting outside entities from making changes to it.