Accessor and mutator functions can be used in conjunction and are often
associated with the words SET and GET. Describe each of these functions
and provide an example of a situation in which they can be used
Getters and Setters are the cornerstone of data access in object oriented programming. These are important, because it allows different objects to interact with data stored inside of an object without directly touching the variable.
Think of it like this: There is a Fred object and he has a variable "wallet". Now he doesn't want people directly changing what's in his wallet. So, they have to ask him to get it's value or to change it. That's the same as getter's and setter's.
The getter is used to get the current value of the object's member variable. The setter is used to change it. A simple example is if the program wants to set the value, but only if it is empty. First, it would check the value with the getter. If it is empty, it would call the setter with the new value to change it to.
Mar 15th, 2015
Did you know? You can earn $20 for every friend you invite to Studypool!