What is the real point of encapsulation? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What is the real point of encapsulation?

Whats the point of hiding members from outside of class if other programmers can edit that class, with only changing private to public members? And end-users can only access the interface. Even without encapsulation, they can't access/alter public variables if there's no way to do it.

13th Apr 2019, 6:48 AM
Christian Vibora
Christian Vibora - avatar
4 Answers
+ 11
Encapsulation is defined as the wrapping up of data under a single unit. It is the mechanism that binds together code and the data it manipulates.Other way to think about encapsulation is, it is a protective shield that prevents the data from being accessed by the code outside this shield. Technically in encapsulation, the variables or data of a class is hidden from any other class and can be accessed only through any member function of own class in which they are declared.As in encapsulation, the data in a class is hidden from other classes, so it is also known as data-hiding.
13th Apr 2019, 8:01 AM
Shadow Ninja[#Inactive]
Shadow Ninja[#Inactive] - avatar
Encapsulation will ensure that there's no misuse or interference of data. More so the data you wouldn't like to be modified externally.
13th Apr 2019, 7:15 AM
washie mugo
washie mugo - avatar
I mean what's the point of hiding it from other classes? Or to anything? The modifiers can be edited.
13th Apr 2019, 9:08 AM
Christian Vibora
Christian Vibora - avatar
Okay well the explanation about IDE's are great! So it's safe to say that encapsulation has nothing to do with the end-users.
13th Apr 2019, 10:00 AM
Christian Vibora
Christian Vibora - avatar