Implementing get/set function.

Pages: 12
closed account (zb0S216C)
dudeman007 wrote:
"How is the best way to implement get/set functions?"

The best way is not to implement them. If you're going to provide the user a means to modify a private data member through a member function, then declaring it public will have the same effect. The whole idea behind level-of-access is to restrict access to the data members that are private or protected; this is encapsulation. By providing get/setters, you're breaking that encapsulation. On the flip-side, getters aren't all that bad so long as you return a copy of the data member.

Last edited on
Thanks to everyone, I appreciate the suggestions and information!!
Topic archived. No new replies allowed.
Pages: 12