Episode 17 – Component Coupling

Clean Code

Episode 17

This episode talks about how components should depend on each other.

  • Overview
    • Acyclic Dependencies Principle
    • Stable Dependencies Principle
    • Stable Abstractions Principle
  • The Acyclic Dependencies Principle
    • Cyclic module cause those module to force to release at the same time
    • Solution is either split the component out or use dependency inversion
  • The Stable Dependencies Principle
    • Stability is something that is hard to change.
    • A component should depend on something more stable
    • Stability correlates with number of incoming dependency and inversely correlates to number of outgoing dependency.
  • The I metrics
    • I metrics = Fan-out / ( Fan-in + Fan-out )
    • All dependency arrow point toward decreasing I.
  • The Stable Abstractions Principle
    • Use open-close principle for the module at the bottom of the dependency.
    • The more stable a component, the more abstract it should be.
    • Abstract number = number of abstract classes / number total classes
    • A + I = 1
  • Distance
    • D = | A + I | – 1
    • Zone of uselessness is where there many abstraction but nothing using it
    • Zone of pain is there are too many concrete classes depend on each other
    • Distance metric between zone of uselessness and zone of pain
  • References