Table of Contents
Add More Classes
Variants and Alternative Names
“When things get too complex, add more classes.”1)
Complexity can often be reduced by adding further classes that better separate concerns.
- Divide larger classes into several smaller ones.
- Use polymorphism, dynamic binding and abstract couplings.
- Adding too many classes leads to ravioli code. Which may be hard to grasp and debug.
- Classes need to be separately understandable (see PSU).
See section contrary principles.
Grady Booch is sometimes cited like that. The precise origin is unknown. See AddMoreClasses.
Relations to Other Principles
- High Cohesion (HC): Add more classes is a direct result of HC.
- More Is More Complex (MIMC): Add More Classes decreases complexity with respect to the size of the classes on expense of increased complexity due to the number of classes. There is always a tradeoff to be made. Add More Classes tells that an increased number of classes often is the lesser evil while MIMC explains the tradeoff to be made.
Discuss this wiki article and the principle on the corresponding talk page.