Keep related data and behavior in one place
From CSSEMediaWiki
(Difference between revisions)
m |
|||
Line 2: | Line 2: | ||
If two or more areas are actually of the same key abstraction they should be captured in the same class. As soon as there are any "get" operations that might imply that this heuristic is being violated. | If two or more areas are actually of the same key abstraction they should be captured in the same class. As soon as there are any "get" operations that might imply that this heuristic is being violated. | ||
+ | |||
+ | -- ''Explanation'': If the object retrieved by the get operation is further used to call another function or obtain another object then this is a violation. A rule of thump is whenever you see consecutive use of "." operations then it's very likely to be a violation of this rule. A simple example is: | ||
+ | student.getMarks().calculateGrade() | ||
+ | |||
==See also== | ==See also== |
Revision as of 12:54, 11 October 2010
- Keep related data and behavior in one place. --Riel's Heuristic 2.9, Arthur Riel 1996
If two or more areas are actually of the same key abstraction they should be captured in the same class. As soon as there are any "get" operations that might imply that this heuristic is being violated.
-- Explanation: If the object retrieved by the get operation is further used to call another function or obtain another object then this is a violation. A rule of thump is whenever you see consecutive use of "." operations then it's very likely to be a violation of this rule. A simple example is:
student.getMarks().calculateGrade()