+ 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 odpowiedzi
+ 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
0
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
0
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
0
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