Data 'hiding' aspires to reduce complexity by reducing the risk of some dataset getting into an invalid/undesirable state. It is enforced by language semantics in C++, Java, C# etc by use of the 'private' keyword. This mechanism restricts the scope for modifying the dataset's state to code that's part of the dataset, in OO languages the dataset is termed an 'object'.I do not understand the difference between data hiding and Encapsulation. Are these two same or different? If these two are different then what is the difference between the two
Encapsulation Is the process of hiding sensitive data of object from user. To achieve this, we must declare class variables/attributes as private.
Here's an example of typical encapsulation:
Can you help me to understand the difference between the two. How they are different from each other ?Code:class MyClass { public: int a //public member private: int x; //private member int y; };
Encapsulation is closely related but is a less formal term I think.
These terms are commonly associated with OO languages which belong to the class of imperative languages, contrast this with functional languages in which hiding is less of a concern because changing state is rare or even impossible because there are no variables - values are immutable.