News for hackers. Stuff that matters.
Re:Avoid getters and setters whenever possible by phkahler on Thursday March 22, 2018 @08:16AM (#16647912)
>> consider cases where you need values to be restricted or linked...

In other words when the values are part of a larger data structure that will break consistency if not updated via the proper functions. a.k.a. there are supposed to be side effects (of a sort) when the value is changed. This has always been my understanding of where the concept came from. It's encapsulation/protection of structure, not of a specific variable.

There are times when you want to change things only via an API and there are times when you don't care. You will usually know in advance but not always. As an example, try making a diagram editor and later decide you'd like to implement undo/redo after the fact.

There are no comments on this comment yet.