Why do we need private variables?
Posted
by
rak
on Programmers
See other posts from Programmers
or by rak
Published on 2012-04-10T05:31:08Z
Indexed on
2012/04/10
5:42 UTC
Read the original article
Hit count: 186
Why do we need private variables in classes in the context of programming?
Every book on programming I've read says this is a private variable, this is how you define it but stops there.
The wording of these explanations always seemed to me like we really have a crisis of trust in our profession. The explanations always sounded like other programmers are out to mess up our code. Yet, there are many programming languages that do not have private variables.
What do private variables help prevent?
How do you decide if a particular of properties should be private or not? If by default every field SHOULD be private then why are there public data members in a class?
Under what circumstances should a variable be made public?
© Programmers or respective owner