Could you please check if the following code is correct or not? The fact is that I found something similar in propduction code and I have doubt if it matches Open/Closed principle.
public abstract class CustomClass {
private ClassThatSetEnvironmentProperty sysProp = new ClassThatSetEnvironmentProperty("SYS_PROPETY", "SYS_PROPERTY_VALUE");
// some code here
void setSysProp(ClassThatSetEnvironmentProperty sysProp) {
this.sysProp = sysProp;
}
}
My understanding is the setter is defined for unit-tests possibilities only (to mock ClassThatSetEnvironmentProperty
). But in this case the setter allows concrete inheritants to change defined state. From my perspective it violates encapsulation. More over I think that it is also violates open/closed prinicple. Frankly, some of my coleagues takes an opposite view. I really have not to much experience so it is hard for me to recognise it. Please share your opinion here. Thank you.