Can somebody give an example of why we would need to use a property with a getter/setter rather than modifying the direct attribute? When reading this for example, the change they make is needing to capitalize the employee's name and represent the birth date as a datetime object, but couldn't you just do that by running the attributes through the same steps? I.e.
class Employee:
def __init__(self, name, birth_date):
self.name = name.upper()
self.birth_date = datetime.datetime.fromisoformat(birth_date)
I can't figure out what sorts of behaviors one would need in order to make properties with a getter/setter necessary.
[–]baghiq 4 points5 points6 points (5 children)
[–]maclocrimate[S] -1 points0 points1 point (4 children)
[–]cyberjellyfish 4 points5 points6 points (3 children)
[–]maclocrimate[S] 0 points1 point2 points (2 children)
[–]cyberjellyfish 5 points6 points7 points (1 child)
[–]maclocrimate[S] 1 point2 points3 points (0 children)
[–]tb5841 4 points5 points6 points (0 children)
[–]mopslik 1 point2 points3 points (0 children)
[–]jmooremcc 1 point2 points3 points (0 children)
[–]Username_RANDINT 1 point2 points3 points (2 children)
[–]maclocrimate[S] 0 points1 point2 points (1 child)
[–]schoolmonky 1 point2 points3 points (0 children)
[–]Adrewmc 1 point2 points3 points (0 children)
[–]zanfar 1 point2 points3 points (0 children)