If I have an instance variable that has personal visibility, should I use the installer to change its value or just change the value directly?
The instance variable in this example will only ever be changed in this class, and thus the installer will be closed. I assume that using a setter is the right way, as it localizes how / when it is changed, but this is just something that somehow calls me by mistake!
Please see below code which may help convey my question more clear
public class A {
private int i;
public A() {
i = 5
}
private void doSomeCalculationsA() {
i = 7
}
private void doSomeCalculationsB() {
setI(5)
}
private void setI(int newValue) {
i = newValue;
}
}
LDM91 source
share