title: Is it good practice to create functions to access class variables?
body: <p>As the title says: Is it good practice to create functions to access class variables?</p>
  
  <p>I have seen quite a number of pieces of code that do something like the following:</p>
  
  <pre><code>class MyClass {
  public:
  void setx(int a);
  void sety(int b);
  int read_x;
  int read_y;
  
  private:
  int x;
  int y;
  
  };
  
  void MyClass::setx(int a) {
  x=a;
  }
  
  void MyClass::sety(int b) {
  y = b;
  }
  
  int MyClass::read_x() {
  return x;
  {
  
  int MyClass::read_y() {
  return y;
  }
  </code></pre>
  
  <p>So rather than accessing variables directly(MyClass.x) they use functions to read and set the variable values etc.</p>
  
  <p><strong>Is this a standard or good practice?</strong></p>