Upgrade to Pro — share decks privately, control downloads, hide ads and more …

今更考える「単一責任原則」 / Thinking about the Single Resp...

Avatar for philomagi philomagi
February 19, 2026

今更考える「単一責任原則」 / Thinking about the Single Responsibility Principle

# 参考文献

- Robert C. Martin(2003)『Agile Software Development, Principles, Patterns, and Practices』
- Robert C. Martin(2014)『The Single Responsibility Principle』(The Clean Code Blog)
- Robert C. Martin(2017)『クリーンアーキテクチャ 達人に学ぶソフトウェアの構造と設計』(アスキードワンゴ)

# zenn版

https://zenn.dev/philomagi/articles/restudy_single_responsibility_principle

Avatar for philomagi

philomagi

February 19, 2026
Tweet

More Decks by philomagi

Other Decks in Programming

Transcript

  1. SRP v1 (2003 )の定義 「Agile Software Development, Principles, Patterns, and

    Practices (以下、 「ASD 」 ) 」の記述 In the context of the SRP, we define a responsibility to be "a reason for change." If you can think of more than one motive for changing a class, then that class has more then one responsibility. “ “ SRP の文脈では、責任を「変更の理由」と定義する。あるクラス を変更する動機が複数思い浮かぶ場合、そのクラスは複数の責任 を負っている。 “ “
  2. SRP v1 の焦点(Rectangle の例から) 本来不要なライブラリ・ソースとのリンクを防ぐ(ASD, p96 ) GUI と幾何計算が同じクラスに混在する GUI

    変更が計算アプリへ再ビルドを強いる 無関係な変更による予期せぬ副作用を防ぐ(ASD, p96 ) 再コンパイル・再テスト・再デプロイなど SRP v1 の主目的は、関係のない理由による変更から、クラスとその クライアントを保護することと考えられる 主に技術的観点からの整理
  3. v1 の適用判断 変更が実際に起きる時だけ「変更軸」になる(ASD, p97 ) 症状が無い段階での分離は賢明ではない(ASD, p97 ) 分離しすぎは不必要な複雑性になる An

    axis of change is an axis of change only if the changes actually occur “ “ It is not wise to apply the SRP, or any other principle for that matter, if there is no symptom “ “
  4. v1 からの転換点(2014 ) 『The Single Responsibility Principle 』 (The Clean

    Code Blog) 「この原則は人々に関するもの」と明言される 変更の理由が「人々」に結びつけられる 技術中心の視点から組織中心の視点へ移る And this gets to the crux of the Single Responsibility Principle. This principle is about people “ “
  5. Employee 例の採用(Blog, 2014 ) public class Employee { public Money

    calculatePay(); public void save(); public String reportHours(); } calculatePay() はCFO の関心を代表する(財務責任) reportHours() はCOO の関心を代表する(運用責任) save() はCTO の関心を代表する(技術責任) このEmployee はSRP 違反を犯している
  6. SRP v2 (2017 )の定義 『クリーンアーキテクチャ 達人に学ぶソフトウェアの構造と設計』 (CA ) アクターは「変更を望む人々のグループ」とされる(CA, p82

    ) v1 では「変更理由」とされていたものが、CA では組織単位へ具体 化される モジュールはたったひとつのアクターに対して責務を負うべき である(CA, p82 ) “ “
  7. SRP v1 とv2 の違い 観点 v1 (変更の理由) v2 (アクター) 焦点

    技術的結合 組織的結合 例 Rectangle Employee 変更の 起源 技術的決定(ライブラリ、アル ゴリズム) 組織的要求(部門の業 務要件) 判断基 準 技術的変更パターン 業務機能を代表するグ ループ
  8. 参考文献 Robert C. Martin (2003 ) 『Agile Software Development, Principles,

    Patterns, and Practices 』 Robert C. Martin (2014 ) 『The Single Responsibility Principle 』 (The Clean Code Blog ) Robert C. Martin (2017 ) 『クリーンアーキテクチャ 達人に学ぶソ フトウェアの構造と設計』( アスキードワンゴ)