Getter and setter policy

From CSSEMediaWiki
(Difference between revisions)
Jump to: navigation, search
(Well there is a starting policy, now we get to decide if it is right.)
Line 1: Line 1:
Objects should store all their data in private variables. Getter and setter methods should be produced for any variable you might have been tempted to declare public. Classes should ideally call their own getter and setters when accessing their internal data. This prevents the object getting into a invalid state.  
+
Needing to have getters and setters is bad as they increase coupling. However if need to implement them apply the following guides.
  
Some complications may be encountered when classes contain collections that require non-transactional access.
+
Objects should store all their data in private or protected variables. Getter and setter methods should be produced for any variable you may consider you have a legitimate reason to declare public. Classes should ideally call their own getter and setters when accessing their internal data. This prevents the object getting into a invalid state.

Revision as of 04:33, 30 July 2009

Needing to have getters and setters is bad as they increase coupling. However if need to implement them apply the following guides.

Objects should store all their data in private or protected variables. Getter and setter methods should be produced for any variable you may consider you have a legitimate reason to declare public. Classes should ideally call their own getter and setters when accessing their internal data. This prevents the object getting into a invalid state.

Personal tools