Page 1 of 1

Private and public affairs in instance variables

PostPosted: 21 Feb 2013, 15:32
by Ursego
Avoid public instance variables.

Create them only private (or protected if you are planning the class to be extended and the descendants can have a need to access the variable directly). The purpose of instance/static variables is to keep internal information of the object/class, so the outer world (other classes) should access this information only using public properties (or public methods, if your programming language doesn't have properties), i.e. in a controllable way.