Feb-17-2017, 07:42 AM
(Feb-16-2017, 10:54 PM)Larz60+ Wrote:Quote:is strongly advice to always use getters and setters and not access data attribute directly.
I do use them when appropriate, but only then.
The second part of the phrase is right, but the first is not. Getters and setters aren't any better than accessing attributes directly. Data encapsulation isn't about changing the class attributes transparently, it is about object state integrity. If you have a
Person
class with name
and surname
attributes, you shouldn't be able to change these independently (which is what can still happen with setters), otherwise when you change John Doe
to Jean Dupont
there is a time window where the person is Jean Doe
(or John Dupont
). Person
should have a rename(firstname,surname)
method (possibly with locks...).
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Your one-stop place for all your GIMP needs: gimp-forum.net