For a long time, I kept thinking “there is no point to a private variable if all you do is get/set it”
yeah yeah encapsulation encapsulation and whatever. But what if the get/set is just a pass-through? Surely its better in that case to use a public field.
HOWEVER. There is more to encapsulation
- With the GET/SET, you remove “dependence” of your client on your field names. This means you have the OPPORTUNITY to change internally how you manage a variable. This makes it so your client (user of your class) DOES NOT NEED TO adjust his code, in case you need to change how a particular member is treated internally to your class