Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
def Class
#5
Getters and setters are not needed for this simple example, but may be the best solution when setting the value of an attribute is accompanied by some action. For example, setting the value of an LED class object should turn the lamp on. I also like using getters and setters when a class is intimately tied to a user interface.

I would say that getters and setters have as much a place in Python as they do in any other language. They aren't required for accessing attributes, but there are plenty of programming problems where setters, in particular, are a good design choice.

Having said that, I do not like Python properties. They don't work well as a callback and the calling syntax provides no hint that something other than setting the attribute value may be happening.
Reply


Messages In This Thread
def Class - by trazom - Aug-24-2020, 03:35 PM
RE: def Class - by deanhystad - Aug-24-2020, 04:16 PM
RE: def Class - by trazom - Aug-26-2020, 05:39 PM
RE: def Class - by buran - Aug-26-2020, 05:55 PM
RE: def Class - by deanhystad - Aug-27-2020, 03:17 PM

Forum Jump:

User Panel Messages

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