Limit compositions in a class

From CSSEMediaWiki
Revision as of 07:04, 24 November 2010 by Ebybymic (Talk | contribs)
Jump to: navigation, search

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