I have a class A
with a property named prop
of type int
. Getters and setters are usually implemented as follows:
class A
{
void set_prop(int value); // set
int get_prop() const; // get
}
Is there a reason to prefer this design, instead of using two overloads with the same name, as follows?
class A
{
void prop(int value); // set
int prop() const; // get
}
I like the last form better (maybe it's just a matter of taste). But I have usually seen the first form. So I am wondering if there is a deep reason to prefer one over the other? That is, is this just a matter of style, or is there an Object Oriented principle that says one is better than the other?