The point of providing a public method to change a private variable is that you can add additional controls.
There is not a lot of difference between
class A {
public:
int age;
}
and
class B {
private:
int age;
public:
void setAge(int _age);
}
B::setAge(int _age) {
this->age = _age;
}
But, in the second case, you can add logic that rejects some data (v.g. a negative value) or updates other fields. So you can ensure that the data of your object will remain consistent. If you follow the first approach, that logic should replicated every time the property is accessed directly (note: many programmers will forget to do so).