Edit: I suppose it may be argued that you need to set some other state when you set a member variable. If that's the case, then it's no longer a getter or a setter and the function should be treated differently.
Edit: I suppose it may be argued that you need to set some other state when you set a member variable. If that's the case, then it's no longer a getter or a setter and the function should be treated differently.
You can say that's not a getter/setter, but then your definition is just different than the people you're responding to.
Of course, in more limited languages/environments they're probably the only tool you have, so there's that.
interface Store { Query() }
// these all have the Query() method
type/class MySQL implements Store
type/class Cache implements Store
type/class Logger implements Store
var db Store
db = new Logger(new Cache(new MySQL()))
I get they can be cumbersome, but using them really matters especially as a project grows... an API that has a simple single client today may have many different (and concurrent!) ones tomorrow. The pain of using S&Gs now saves refactoring later.
At what point is it cheaper to just refactor into getters/setters later when needed? That point _has_ to be miles behind me.
Another problem (from a class/library-consumer point of view) is having getters/setters suddenly becoming more expensive to call, blocking, or even having side effects after an update.
It often only affect the runtime behavior of the code.
Changing the interface, however, will give me a hit that something else has changed.
That isn't the only type of OO. Look at CLOS in Common Lisp for a counterexample: https://wiki.c2.com/?HowObjectOrientedIsClos
Maybe for debugging you want to log a callstack every time the field gets accessed, for example.
Or when you set the field, you should invalidate some cached value that uses it.