← Back to notes

Stable Dependencies Principle (SDP)

Clean Architecture 達人に学ぶソフトウェアの構造と設計

Clean Architecture 達人に学ぶソフトウェアの構造と設計

Depend in the direction of higher stability.

  • A component expected to change should not be depended on by other components that are hard to change.
  • Even a module designed to be easy to modify becomes hard to change if dependent on by other components.
  • If SDP is satisfied, modules intended to be easy to change will not be depended on by inflexible modules.
  • The instability I of a component should be greater than that of the components it depends on.
  • As you follow dependency direction in component structure, I should decrease.
  • In design, keep both highly stable and low-stable components, not just one side.

Stability metric

One method for measuring component stability is to examine how many components this component depends on, and how many depend on it.

  • Fan-In
    • Incoming dependencies: the number of external components depending on classes in this component.
  • Fan-Out
    • Outgoing dependencies: the number of external components that classes in this component depend on.
  • I (Instability)
    • Instability.
    • I = Fan-Out ÷ (Fan-In + Fan-Out)
    • I = 0 is the most stable component
    • I = 1 is the least stable component

To compute fan-in and fan-out, count the classes in the component and the classes in dependent external components.

Amazon アソシエイトについて

この記事には Amazon アソシエイトのリンクが含まれています。Amazonのアソシエイトとして、SuzumiyaAoba は適格販売により収入を得ています。