c++ - Why not set class members to public in the first place? -


this question has answer here:

i can't understand why people keep saying when make class should make get() method variable in class, , set() method set variable in class.

if have get()/set() method... why not make variable public in first place?

it's not if accidentally change anyway since still need type myclassname.variable

am missing something?

using get/set functions gives flexibility change class implementation later without having change code accesses class.

for example, might change type of 1 of internal variables, or want add restrictions on values variable can set to. perhaps might want calculate value on demand.

also, can make get/set function non-inline, , put breakpoint on it.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -