News for hackers. Stuff that matters.
Re:“What if it changes?” by karpierz on Sunday May 22, 2022 @07:56PM (#31474038)
Getters and setters are much more useful when accessing or setting the element should require some other function calls. Caching, memoization, and event-logging are examples where you might want this to happen.

You can say that's not a getter/setter, but then your definition is just different than the people you're responding to.

Re:“What if it changes?” by Xeoncross on Sunday May 22, 2022 @10:29PM (#31474832)
Caching, memoization, and event-logging can be handled by wrapper objects that implement the interface so the base object doesn't need to contain all these layers of outside concerns. Let each class focus on it's single area of use.

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()))

Re:“What if it changes?” by ratww on Sunday May 22, 2022 @10:03PM (#31474677)
However Getters/Setters are often the worst place to implement cross-cutting concerns, like caching, memoization and logging.

Of course, in more limited languages/environments they're probably the only tool you have, so there's that.