So I'm in school for computer science and we are learning about classes(in python more specifically). I would say that I'm an intermediate level programmer and I've worked with classes before but now they are telling me to do something I've never done
Usually, when I work with classes and I want to get a value I just call the value by name i.e.foo.val
but now I'm being told that this is bad practice and I should be writing getter methods.
class ClassName:
def __init__(self, val1, val2):
self._val1 = val1
self._val2 = val2
def getVal1(self):
return self._val1
def getAccountNumber(self):
return self._val2
What I really would like to know is what is the benefit of using a getter method as opposed to just getting the variable by name