"Functions" Please respond to the following:

Computer Science
Tutor: None Selected Time limit: 1 Day

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 together.

Mar 14th, 2015

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!
Click here to
Refer a Friend
...
Mar 14th, 2015
...
Mar 14th, 2015
Dec 7th, 2016
check_circle
Mark as Final Answer
check_circle
Unmark as Final Answer
check_circle
Final Answer

Secure Information

Content will be erased after question is completed.

check_circle
Final Answer