Private and public affairs in instance variables

Share this topic:



Link to this posting

Postby Ursego » 21 Feb 2013, 15:32

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.
User avatar
Ursego
Site Admin
 
Posts: 112
Joined: 19 Feb 2013, 20:33

Return to Coding Style

Who is online

Users browsing this forum: No registered users and 1 guest


Private and public affairs in instance variables

Share this topic:


If you think that this site is not too bad, please LIKE it in Facebook. Thanks!





cron
free counters

eXTReMe Tracker