Why do we need private variables? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why do we need private variables?

20th Jul 2018, 4:14 PM
Keep It Simple Stupid
Keep It Simple Stupid - avatar
2 Answers
+ 2
There are some variables that are not meant to be used by other classes. Accessing and modifying them could mess up the program in some cases, but mostly it is against the principle of information hiding and encapsulation. Should every cell broadcast exactly what its lysosomes are doing to every other cell? No, other cells only need to know what type of cell it is and whether it’s infected. Or, do you want to know the state of every single atom in a chair? No, you just need to know if it’s broken or dirty.
20th Jul 2018, 4:22 PM
Alexander
Alexander - avatar
0
Thanks 👍🏻
20th Jul 2018, 4:30 PM
Keep It Simple Stupid
Keep It Simple Stupid - avatar