When you define a C++ class so that the result is an ADT, which of the following remarks about whether to make a member variable or function public or private are correct?
a. Make them all public. It simplifies life and makes things more efficient to be able access members anywhere.
b. Don’t make member variables public.
c. Make all member functions public.
d. There are some member functions that shouldn’t be public, but most should be public.
Probably b) is correct, see Explanations. d) is correct.
Explanation:
If you follow a) you are not encapsulating anything. You won’t have an ADT if you do this. b) is likely to be a good rule to follow. c) is too restrictive. There are helper functions, or as the text calls them, auxiliary functions that help member functions do their job that should not be public, but most member functions should be public, and member variables private.
You might also like to view...
All of the following are included in the Security category of the Windows Action Center, EXCEPT ________
A) network firewall B) Internet security settings C) virus protection D) system backup
The size and placement of a game trigger are important
Indicate whether the statement is true or false