From Pattern Repository Wiki
Jump to: navigation, search

Blog Posting on Code Qualities: The Christmas Tree Lights Analogy

Webinar: Code Qualities

Quality Description Principles Practices Pathologies


  • All of the elements in a class or method are related to each other.
    • A "strongly cohesive class is one where all of its internal aspects (state, functions, relationships) are about fulfilling the same, single responsibility.
    • A strongly cohedive method is about implementing a single function aspect of a class's responsibilty
  • Poor cohesion is termed weak.
  • Single Responsibility Principle
  • Programming by Intention
  • Up-Front Testing
  • Commonality-Variability Analysis
  • Large classes: A Large class may be large because it has more than one responsibility.
  • Long Methods: A long method may contain more than one function.
  • Difficulty naming: It is hard to give a class or method an intention-revealing name if it does many unrelated things.
  • Large Tests: If a class contains more than one responsibility, the test for that class must test them all, and all of their possible combinations. This often results in tests that are sifnificantly longer than the classes they test.


  • The dependencies between this class and other classes is logical, obvious, and minimal.
    • Identity Coupling exists when one type couples to the existence of another type.
    • Representational Coupling exists when one type couples to the interface of another type.
    • Inheritance Coupling is the coupling that is created between a derived class and its base class.
    • Subclass Coupling exitsts when one type is coupled to the fact that another type is polymorphic, not simple.
  • Good coupling is often termed loose, but we prefer intentional.
  • Bad coupling is often termed tight, but we prefer accidental.
  • Encapsulate by policy, reveal by need.
  • Design to Interfaces.
  • Unexpected side-effects
  • Slow, complex tests


  • Anything that could change (read: anything) should be in a single place in the system.
    • State
    • Function
    • Rules
    • Object creation (memory allocation)
    • Relationships
    • etc...
  • One Rule, One Place
  • Elimitate (refactor) duplication immediately
  • Duplication in client objects
  • Duplication in tests