Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MIT course
#6
(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
Reply


Messages In This Thread
MIT course - by snippsat - Feb-16-2017, 10:06 PM
RE: MIT course - by ichabod801 - Feb-16-2017, 10:13 PM
RE: MIT course - by Larz60+ - Feb-16-2017, 10:54 PM
RE: MIT course - by Ofnuts - Feb-17-2017, 07:42 AM
RE: MIT course - by snippsat - Feb-16-2017, 11:37 PM
RE: MIT course - by micseydel - Feb-17-2017, 07:13 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020