Saturday, June 16, 2007

declare data members private

if everything in public interface is a function than clients don't have to think whether to put parenthesis or not when referring to api

encapsulation is the big reason ....if data members are private they can be replaced with computations/function calls/ different member  (say normal ptr by tr1 ptr) later on


this will let you notify other objects when data members are read or written and check port and pre conditions or other things if you want to.

practically encapsulated means unchangeable.....


protected data members are bad for similar reasons.

protected is no more encapsulated than public ..i don't understand this???

things to remember:

declare data members private. it gives clients syntactically uniform access to data members affords fine grained access control , allows invariant's to be enforced and offers class authors implementation flexibility.


protected is no more encapsulated than public

No comments: