Explain why a class might provide a set function and a get function for a data member.

What will be an ideal response?


A data member is typically declared private in a class so that only the member functions of the class in which the data member is declared can manipulate the variable. A class typically provides a set function and a get function for a data member to allow clients of the class to manipulate the data member in a controlled manner. A set function should validate the data it is setting to ensure that invalid data is not placed in the object. A get function can return the value of a data member without allowing clients to interact with the data member directly. In addition, set and get functions hide the internal data representation. For example, a Time class might represent the time as the total number of seconds since midnight. Such a class can provide member functions getHour, getMinute and getSecond to calculate the hour, minute and second, respectively—even if the underlying data representation does not contain hour, minute and second data members. Similarly, a Time class could provide member functions setHour, setMinute and setSecond to set the current hour, minute or second value. This would require each set function to perform calculations that update the data member containing the total number of seconds since midnight.

Computer Science & Information Technology

You might also like to view...

For each of the factors that contribute to the time taken to transmit a message between two processes over a communication channel, state what measures would be needed to set a bound on its contribution to the total time. Why are these measures not provided in current general-purpose distributed systems?

What will be an ideal response?

Computer Science & Information Technology

To apply the rich text format, you click the Data tab on the Property Sheet and change the ________ property to Rich Text

A) Data format B) Text layout C) Data layout D) Text format

Computer Science & Information Technology

You can install multiple WAPs to permit ?______________? between one WAP?s coverage area and another?s.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology

Which of the following is not a test of access controls?

A. biometric controls B. encryption controls C. backup controls D. inference controls

Computer Science & Information Technology