====== Add More Classes ====== ===== Variants and Alternative Names ===== ===== Context ===== /* fill in contexts here: */ * [[contexts:Object-Oriented Design]] ===== Principle Statement ===== > "When things get too complex, add more classes."((Grady Booch as cited in [[wiki>AddMoreClasses]])) ===== Description ===== Complexity can often be reduced by adding further classes that better separate concerns. ===== Rationale ===== ===== Strategies ===== * Divide larger classes into several smaller ones. * Use polymorphism, dynamic binding and abstract couplings. ===== Caveats ===== * Adding too many classes leads to ravioli code. Which may be hard to grasp and debug. * Classes need to be separately understandable (see [[Principle of Separate Understandability|PSU]]). See section [[#contrary principles]]. ===== Origin ===== Grady Booch is sometimes cited like that. The precise origin is unknown. See [[wiki>AddMoreClasses]]. ===== Evidence ===== /* Comment out what is not applicable and explain the rest: */ /* * [[wiki:Proposed]] * [[wiki:Examined]] * [[wiki:Accepted]] * [[wiki:Questioned]] */ ===== Relations to Other Principles ===== ==== Generalizations ==== * [[High Cohesion]] (HC): Add more classes is a direct result of HC. ==== Specializations ==== ==== Contrary Principles ==== * [[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. ==== Complementary Principles ==== * [[Encapsulate the Concept that Varies]] (ECV): ECV tells how to separate concerns when add more classes shall be used to lower complexity. * [[Model Principle]] (MP): While adding classes MP should be considered in order to find appropriate concepts for encapsulation into a class. ==== Principle Collections ==== ===== Examples ===== ===== Description Status ===== /* Choose one of the following and comment out the rest: */ [[wiki:Stub]] /*[[wiki:Incomplete]]*/ /*[[wiki:Complete]]*/ ===== Further Reading ===== * [[wiki>AddMoreClasses]] * [[wiki>FearOfAddingClasses]] * [[wiki>HowToAvoidFearOfAddingClasses]] * [[wiki>MinimumNumberOfClassesAndMethods]] * [[wiki>RavioliCode]] * [[wp>Ravioli code]] ===== Discussion ===== Discuss this wiki article and the principle on the corresponding [[talk:principles:Add More Classes|talk page]].