menu

hjk41的日志

Avatar

Effective C++ Note 20: Avoid data members in the public interface

1. for constency
If everything in the public interface are functions, clients of your classes won't have to remember whether they should use parentheses when they want to access a data member.

2. to control the accessibility of the data members
If you make a data member public, everyone will have read-write access to it.

3. for functional abstraction
If you use functions to get and set data members, you can modify the implemetation of the class much more easier.

评论已关闭