If a variable has getter and setter, should it be public?
<p>I am an about to graduate Computer Science student so probably this is a stupid question.
If I have a class with a variable that is private and the class have getter and setter for that variable. Why don't make that variable public?</p>

<p>The only case I think you have to use getters and setters is if you need to do some operation besides the set or the get. Example:</p>

<pre><code>void my_class::set_variable(int x){
   /* Some operation like updating a log */
   this-&gt;variable = x;
}
</code></pre>

<p>Thanks in advance!</p>
