Why we need protection for data variable s ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why we need protection for data variable s ?

who's gonna be broken the security of encapsulation? who is out side users ?

26th May 2017, 5:40 AM
MUJEEB I S - avatar
1 Answer
It's more about architecture. Encapsulation hides variables or some implementation that may be changed so often in a class to prevent outsiders access it directly. They must access it via getter and setter methods. It is important to take into consideration what parts of your program are doing what. You should generally split up your code into logically consistent chunks.
26th May 2017, 3:08 PM
Felipe Cruz
Felipe Cruz - avatar