Limit compositions in a class

From CSSEMediaWiki
(Difference between revisions)
Jump to: navigation, search
m
m (Reverted edits by Ebybymic (Talk); changed back to last version by Stephen Fitchett)
 
(One intermediate revision by one user not shown)

Latest revision as of 03:11, 25 November 2010

Classes should not contain more objects than a developer can fit in his or her short term memory. A favorite value for this number is six. --Riel's Heuristic 4.7, Arthur Riel 1996

This heuristic assumes that most of the methods in a class should be using most of the data members most of the time. This will then require implementors to think about all the data members of the class while writing methods. If there are too many to think about, then this will lead to items being ommited and bugs creeping into the code. Seven plus or minus two is the widely accepted number of items that people can keep in their short term memory. Riel suggests that six is the optimum number as it takes into consideration those with poor short term memories and that there are other factors such as the fact that methods usually take in an argument or two.

Personal tools