Effective C++ Ed. 3rd: Item 22. Declare data members private


Declare members private for :
  1. Syntactic Consistency: Every call-able member would be a function.
  2. Granular Accessibility: Using "setter" and "get" functions
  3. Encapsulation:
    • Implement functions the way it suits best. For example: On embedded devices: it must use less memory whereas on other machines, it may be allowed to take more memory to speed it up more.
    • Private data members put more restriction on their interaction with the users as compared to protected and public data members. So removing private data member (to change some implementation) leads to less broken code relatively.
prev | next
Cheers and try hosting at Linode.

No comments:

Post a Comment