How do you decide on whether an attribute of a class is public or has an accessor method?
For example, a Cody class could be written in two ways (I'm not including variables that you create / modify with get / set methods):
class Cody {
public string colour = white;
public int age = 10;
}
class Cody {
private string colour = white;
private int age = 10;
public void setColour(string colourIn) {
this.colour = colourIn;
}
public string getColour() {
return this.colour;
}
public void setAge(int ageIn) {
this.age = ageIn;
}
public int getAge() {
return this.age;
}
}
Do you just create accessor methods (is that the correct term?) for those attributes that are likely to be complex or may need transformation, or do you create them for everything and leave nothing public?