Information Hiding

Information hiding or data hiding in programming is about protecting data or information from any inadvertent change throughout the program. Information hiding is a powerful OOP feature. Information hiding is closely associated with encapsulation.

Information hiding definition
Information or data hiding is a programming concept which protects the data from direct modification by other parts of the program.

The feature of information hiding is applied using Class in most of the programming languages.

Demo of information hiding in C++:


class student
{
char name[30];
int marks;
public:
void display();
};

int main()
{
student S;
S.marks=50; // Wrong code!
getch();
return 0;
}

The accessibility often plays an important role in information hiding. Here the data element marks is private element and thus it cannot be accessed by main function or any other function except the member function display() of class student. To make it accessible in main function, it should be made a public member.