Private and public affairs in instance variables


Link to this posting

Postby Ursego » 21 Feb 2013, 15:32

Avoid public instance (object member) 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.

You can say: it's super obvious, why did you create this topic? Unfortunately, I have seen many-many violations of this rule in the applications I worked with, especially ones written in PowerBuilder. :cry:
User avatar
Ursego
Site Admin
 
Posts: 143
Joined: 19 Feb 2013, 20:33



Ketones are a more high-octane fuel for your brain than glucose. Become a biohacker and upgrade yourself to version 2.0!



cron
Traffic Counter

eXTReMe Tracker