DEV Community

Discussion on: Avoid getters and setters whenever possible

Collapse
 
gustavoagt profile image
Gustavo Gómez

So, if want to change the implementation later of the reference: "public Engine engine"? but 100,000 other classes have directly access, what do you recommend to do?

if before to get a value i need to make some validation, what do you recommend me to do?

Collapse
 
scottshipp profile image
scottshipp

Sorry if it wasn't clear. First, I would recommend not making it public to begin with, and definitely not for 100,000 other classes to have access. If you need to make some validation before getting the value, definitely keep the variable private and expose a well-named method instead.