Facebook Pixel
Searching...
日本語
EnglishEnglish
EspañolSpanish
简体中文Chinese
FrançaisFrench
DeutschGerman
日本語Japanese
PortuguêsPortuguese
ItalianoItalian
한국어Korean
РусскийRussian
NederlandsDutch
العربيةArabic
PolskiPolish
हिन्दीHindi
Tiếng ViệtVietnamese
SvenskaSwedish
ΕλληνικάGreek
TürkçeTurkish
ไทยThai
ČeštinaCzech
RomânăRomanian
MagyarHungarian
УкраїнськаUkrainian
Bahasa IndonesiaIndonesian
DanskDanish
SuomiFinnish
БългарскиBulgarian
עבריתHebrew
NorskNorwegian
HrvatskiCroatian
CatalàCatalan
SlovenčinaSlovak
LietuviųLithuanian
SlovenščinaSlovenian
СрпскиSerbian
EestiEstonian
LatviešuLatvian
فارسیPersian
മലയാളംMalayalam
தமிழ்Tamil
اردوUrdu
Clean Architecture

Clean Architecture

著者 Robert C. Martin 2017 432 ページ
4.23
6k+ 評価
聞く
聞く

つの重要なポイント

1. ソフトウェアアーキテクチャは人的資源の最小化と生産性の最大化を目指す

ソフトウェアアーキテクチャの目標は、必要なシステムを構築および維持するために必要な人的資源を最小限に抑えることである。

アーキテクチャの決定は重要である。 良いアーキテクチャは、ソフトウェアシステムの開発、展開、および維持に必要な労力を減少させる。これにより、チームは独立して作業でき、変更の影響を最小限に抑え、システムが時間とともに進化することを可能にする。

良いアーキテクチャの主な側面:

  • 関心の分離
  • 依存関係の管理
  • 実装詳細の抽象化
  • 将来の変更に対応する柔軟性

これらの側面に焦点を当てることで、アーキテクトは理解しやすく、変更しやすく、拡張しやすいシステムを作成し、最終的には生産性の向上とシステムのライフタイムコストの削減を実現できる。

2. クリーンアーキテクチャはビジネスルールを外部の詳細から分離する

アプリケーションの中心はデータベースではない。また、使用しているフレームワークのいずれかでもない。アプリケーションの中心はそのユースケースである。

ビジネスルールが核心である。 クリーンアーキテクチャはコードを同心円状に整理し、ビジネスルールを中心に、実装の詳細を外側の層に配置する。この分離により、データベース、ユーザーインターフェース、フレームワークなどの外部要因の変更によってコアビジネスロジックが影響を受けないようにする。

クリーンアーキテクチャの主な層:

  • エンティティ: 企業全体のビジネスルール
  • ユースケース: アプリケーション固有のビジネスルール
  • インターフェースアダプタ: ユースケースと外部エージェンシー間のデータ変換
  • フレームワークとドライバ: 外部ツールと技術

この構造に従うことで、開発者は以下のようなシステムを作成できる:

  • 変更に柔軟に対応できる
  • テストと保守が容易
  • 特定の技術やフレームワークに依存しない

3. SOLID原則は柔軟で保守可能なシステムの作成を導く

SOLID原則は、関数とデータ構造をクラスにどのように配置し、それらのクラスをどのように相互接続するかを教えてくれる。

SOLIDはモジュール性を強化する。 これらの5つの原則は、理解しやすく、柔軟で保守可能なソフトウェアシステムを作成するためのガイドラインを提供する。これにより、変更に強く、拡張しやすいコードを設計するのに役立つ。

SOLID原則は次の通り:

  • 単一責任の原則: クラスは変更の理由を一つだけ持つべき
  • 開放/閉鎖の原則: ソフトウェアエンティティは拡張に対して開かれているが、変更に対して閉じているべき
  • リスコフの置換原則: スーパークラスのオブジェクトは、そのサブクラスのオブジェクトで置き換え可能でなければならない
  • インターフェース分離の原則: 多くのクライアント固有のインターフェースは、一つの汎用インターフェースよりも良い
  • 依存性逆転の原則: 高レベルモジュールは低レベルモジュールに依存すべきでなく、両方が抽象に依存すべき

これらの原則を適用することで、開発者は変更要求に適応できる、より堅牢でスケーラブルなソフトウェアアーキテクチャを作成できる。

4. コンポーネントはクリーンアーキテクチャの構成要素である

コンポーネントはデプロイの単位であり、システムの一部としてデプロイ可能な最小のエンティティである。

モジュラー設計は柔軟性を可能にする。 クリーンアーキテクチャのコンポーネントは、独立してデプロイおよび開発可能なシステムの部分である。これらは関連する機能をカプセル化し、明確なインターフェースを持つため、システムの保守と変更が容易になる。

よく設計されたコンポーネントの主な特徴:

  • 高い凝集性: 関連する機能が一緒にグループ化されている
  • 低い結合性: コンポーネント間の依存関係が最小限
  • 明確なインターフェース: 明確に定義された相互作用方法
  • 独立したデプロイ可能性: 他のシステム部分に影響を与えずに更新または置換可能

システムをコンポーネントに整理することで、アーキテクトは以下を実現できる:

  • 異なるチームによる並行開発を促進
  • テストとデバッグが容易
  • システムの段階的な更新と改善を可能にする
  • システム全体のスケーラビリティと保守性を向上

5. 境界はコアビジネスロジックを定義し保護する

各アーキテクチャの境界には、どこかにHumble Objectパターンが潜んでいる可能性が高い。

境界はコアを保護する。 クリーンアーキテクチャの境界は、特にビジネスロジックと実装の詳細の間で異なる関心領域を分離する。これらの境界は、コアビジネスルールが外部システムや技術の変更によって影響を受けないようにする。

アーキテクチャの境界の主な側面:

  • 層間の相互作用を定義するインターフェースの使用
  • 依存性逆転により依存関係が内向きになるようにする
  • 境界を越えて情報を渡すためのデータ転送オブジェクトの使用
  • テスト可能な動作をハードテストのコンポーネントから分離するHumble Objectの使用

明確な境界を確立することで、アーキテクトは以下を実現できる:

  • 外部システムや技術の変更の影響を最小限に抑える
  • コアビジネスロジックのテストを容易にする
  • 実装の詳細をコアシステムに影響を与えずに置換可能にする
  • システム全体の柔軟性と適応性を向上

6. クリーンアーキテクチャはテスト駆動開発と独立したデプロイを促進する

良いアーキテクチャは、変更が必要なすべての方法でシステムを変更しやすくし、選択肢を開いたままにする。

テスト可能性と柔軟性が鍵である。 クリーンアーキテクチャは、システムをテストしやすく、独立してデプロイしやすくする実践を促進する。関心の分離と依存関係の管理により、コアビジネスロジックの単体テストが容易になり、システムの異なるコンポーネントを個別にデプロイできるようになる。

クリーンアーキテクチャのテストとデプロイの利点:

  • コアビジネスルールはUI、データベース、外部依存関係なしでテスト可能
  • 異なるコンポーネントを独立してデプロイでき、更新が容易
  • システムの一部の変更が他の部分に与える影響が最小限
  • 新機能を追加する際の既存機能の破損リスクが低減

これらの特性により、以下が実現される:

  • 開発サイクルの短縮
  • デプロイのリスクの低減
  • システムの信頼性の向上
  • 新技術の採用や既存技術の変更に対する柔軟性の向上

7. フレームワークとデータベースは実装の詳細であり、アーキテクチャの要素ではない

フレームワークは使用するツールであり、従うべきアーキテクチャではない。

コアロジックはフレームワークに依存しないべきである。 クリーンアーキテクチャは、フレームワークとデータベースをコアビジネスロジックに影響を与えない外部の詳細として扱う。このアプローチにより、これらの外部要素を変更または更新してもシステムのコア機能に影響を与えない柔軟性が得られる。

フレームワークとデータベースの取り扱いに関する主要原則:

  • それらをコアビジネスロジックへのプラグインとして扱う
  • 依存性逆転を使用してコアロジックを独立させる
  • データベース操作の抽象化を作成する
  • フレームワークとデータベースの決定をできるだけ遅らせる

このアプローチの利点:

  • フレームワークとデータベースの変更やアップグレードが容易
  • コアビジネスロジックは外部の変更にもかかわらず安定
  • ベンダーロックインの軽減
  • コアシステムコンポーネントのテスト可能性の向上

8. ウェブはクリーンアーキテクチャにおける単なる配信メカニズムである

ウェブは配信メカニズムであり、アプリケーションアーキテクチャはそれをそのように扱うべきである。

ビジネスロジックは配信に依存しない。 クリーンアーキテクチャでは、ウェブはデータベースやフレームワークと同様に外部の詳細として扱われる。この視点により、コアビジネスロジックはウェブアプリケーション、デスクトップアプリ、APIなどの特定の配信メカニズムに依存しないようになる。

クリーンアーキテクチャにおけるウェブアプリケーションの主な考慮事項:

  • ウェブ固有のコードをコアビジネスロジックから分離する
  • ウェブフォーマットと内部データ構造を変換するためのインターフェースアダプタを使用する
  • ウェブフレームワークをコアシステムへのプラグインとして扱う
  • ユースケースをウェブ固有の懸念から独立させて設計する

このアプローチの利点:

  • 異なる配信メカニズムにシステムを適応させやすい
  • コアビジネスロジックを複数のプラットフォームで再利用可能
  • ウェブ依存なしでビジネスルールのテストが簡単
  • ウェブ技術の変更や更新に対する柔軟性の向上

9. クリーンな組み込みアーキテクチャはハードウェアの懸念をビジネスロジックから分離する

ソフトウェアは摩耗しないが、ハードウェアへの管理されていない依存関係によって内部から破壊される可能性がある。

ハードウェアの独立性は重要である。 クリーンな組み込みアーキテクチャは、組み込みシステムにクリーンアーキテクチャの原則を適用し、ハードウェア固有の懸念をコアビジネスロジックから分離する。この分離により、ハードウェアコンポーネントの更新が容易になり、ソフトウェアの移植性が向上する。

クリーンな組み込みアーキテクチャの主な要素:

  • ハードウェア抽象化レイヤー(HAL)を使用してハードウェア固有のコードを隔離する
  • デバイスに依存しないビジネスロジック
  • ハードウェアとソフトウェアコンポーネント間の明確なインターフェース
  • 依存性逆転を使用してハードウェア依存を管理する

このアプローチの組み込みシステムにおける利点:

  • 新しいハードウェアプラットフォームへのソフトウェアの移植が容易
  • ハードウェア依存なしでコアロジックのテストが簡単
  • ハードウェアの変更がシステム全体に与える影響を軽減
  • 組み込みソフトウェアの保守性と長寿命化の向上

10. マイクロサービスとサービス指向アーキテクチャはクリーンアーキテクチャの原則から利益を得ることができる

システムのアーキテクチャは、ソフトウェア要素を互いに分離し、一方の側が他方の側を知らないようにする境界によって定義される。

クリーンな原則はすべてのスケールに適用される。 クリーンアーキテクチャはモノリシックアプリケーションの文脈でよく議論されるが、その原則はマイクロサービスやサービス指向アーキテクチャにも効果的に適用できる。これらの原則は、個々のサービスの独立性とテスト可能性を維持しながら、分散システムの複雑さを管理するのに役立つ。

マイクロサービスにクリーンアーキテクチャを適用する:

  • 各マイクロサービスを独自のクリーンアーキテクチャを持つ境界コンテキストとして扱う
  • サービス間の通信のための明確なインターフェースを使用する
  • サービス間の依存性逆転を適用する
  • サービスの独立したデプロイ可能性を維持する

マイクロサービスにおけるクリーンアーキテクチャの利点:

  • システム全体のモジュール性とスケーラビリティの向上
  • 個々のサービスの理解と保守が容易
  • サービスの進化と置換の柔軟性の向上
  • サービス間の結合が減少し、より堅牢なシステムが実現

最終更新日:

FAQ

What's Clean Architecture about?

  • Focus on Software Structure: Clean Architecture by Robert C. Martin emphasizes creating systems that are easy to develop, maintain, and deploy through effective software architecture.
  • Timeless Principles: It outlines principles like SOLID, applicable across various programming paradigms, to guide developers in writing clean, maintainable code.
  • Separation of Concerns: The book advocates for separating business rules from technical details, enhancing flexibility and adaptability in software design.

Why should I read Clean Architecture?

  • Improve Software Design Skills: The book enhances understanding of software architecture, providing practical advice for real-world projects.
  • Timeless Knowledge: Its principles are not tied to specific technologies, ensuring relevance throughout your career.
  • Real-World Examples: Martin shares insights from his extensive experience, offering relatable examples and case studies to simplify complex concepts.

What are the key takeaways of Clean Architecture?

  • Architecture is a Shape: Software architecture is defined by component division and communication, facilitating development and maintenance.
  • Decouple Business Rules: Emphasizes separating business rules from technical details for easier changes and adaptations.
  • Leave Options Open: Good architecture defers technical decisions, allowing flexibility to adapt to changing requirements.

What are the SOLID principles mentioned in Clean Architecture?

  • Single Responsibility Principle (SRP): A class should have one reason to change, reducing complexity and easing maintenance.
  • Open-Closed Principle (OCP): Software entities should be open for extension but closed for modification, minimizing bug risks.
  • Liskov Substitution Principle (LSP): Subtypes must be substitutable for their base types without altering program correctness.

What is the Dependency Inversion Principle (DIP) in Clean Architecture?

  • High-Level Modules: DIP states high-level modules should not depend on low-level modules; both should depend on abstractions.
  • Abstractions Over Details: Depending on abstractions rather than concrete implementations makes systems easier to modify and extend.
  • Use of Interfaces: Encourages using interfaces to define contracts between components, enhancing testing and maintenance.

How does Clean Architecture define good software architecture?

  • Support for Use Cases: Good architecture must support intended use cases, making them clear and visible within the structure.
  • Minimize Human Resources: It should minimize resources required for development, deployment, and maintenance through careful design.
  • Leave Options Open: A well-designed architecture keeps options open for future changes, crucial for long-term success.

What is the significance of boundaries in Clean Architecture?

  • Separation of Concerns: Boundaries separate system components, ensuring changes in one area don't adversely affect others.
  • Control Over Dependencies: Managing dependencies across boundaries prevents disruptions, leading to a stable system.
  • Facilitate Independent Development: Boundaries allow teams to work independently, enhancing productivity and reducing conflicts.

What is the "Screaming Architecture" concept in Clean Architecture?

  • Architecture Reflects Intent: "Screaming Architecture" means the system's architecture should clearly communicate its purpose and functionality.
  • Use Case Driven: Good architecture is driven by use cases, maintaining clarity and purpose throughout development.
  • Avoid Framework Dependency: Architecture should be centered around business needs, not dictated by frameworks or tools.

How does Clean Architecture address testing?

  • Testable Architectures: Emphasizes architectures that allow unit testing of business rules without external systems running.
  • Humble Object Pattern: Separates hard-to-test code from testable code, focusing on logic without UI or framework complexities.
  • Testing API: Suggests creating a testing API to bypass security constraints, enhancing the ability to test various scenarios.

How does Clean Architecture differentiate between the web and the architecture of a system?

  • Web as a Delivery Mechanism: The web is viewed as a delivery mechanism, not a defining aspect of system architecture.
  • Decoupling Delivery from Logic: Treating the web as a detail allows designing systems agnostic to delivery methods.
  • Focus on Business Logic: Prioritizes business logic and use cases over web delivery specifics, ensuring core functionality remains intact.

What are the risks of using frameworks according to Clean Architecture?

  • Tight Coupling: Frameworks can lead to tight coupling, making technology switches difficult.
  • Overhead and Complexity: Heavy reliance on frameworks can introduce unnecessary complexity and hinder performance.
  • Loss of Control: Over-reliance on frameworks can lead to a rigid system, making changes and adaptations challenging.

What are the best quotes from Clean Architecture and what do they mean?

  • "Your architecture should tell readers about the system, not about the frameworks you used in your system.": Emphasizes architecture reflecting business domain and use cases, not technologies.
  • "Frameworks are tools, not ways of life.": Reminds developers to maintain control over architecture, not be overly reliant on frameworks.
  • "A good architecture makes it unnecessary to decide on Rails, or Spring, or Hibernate, or Tomcat, or MySQL, until much later in the project.": Highlights deferring technology decisions until architecture is established, promoting flexibility.

レビュー

4.23 中 5
平均評価 6k+ GoodreadsAmazonの評価.

本書『クリーンアーキテクチャ:ソフトウェア構造と設計の職人ガイド』は賛否両論を受けている。多くの人々はSOLID原則とデカップリングに焦点を当てている点を称賛する一方で、繰り返しが多く、実践的な例が不足していると感じる人もいる。歴史的な背景や逸話を評価する読者もいれば、それらが核心内容から逸れていると感じる人もいる。一般的に、本書は高レベルのアーキテクチャ概念を理解するのに役立つと見なされているが、初心者と経験豊富な開発者にとっての有用性については意見が分かれている。いくつかのレビューでは、本書の内容がもっと簡潔に伝えられたかもしれないと指摘されている。

Your rating:

著者について

ロバート・セシル・マーティン(通称アンクル・ボブ)は、著名なソフトウェアエンジニアであり、アジャイル開発手法の提唱者である。オブジェクトメンター社の社長として、オブジェクト指向設計、パターン、UML、アジャイル手法に特化したコンサルタントチームを率いている。マーティンはソフトウェア業界で豊富な経験を持ち、1996年から1999年までC++レポートの編集長を務めた。彼は国際会議や展示会での講演者としても人気があり、ソフトウェア開発のベストプラクティスについての専門知識を共有している。マーティンの影響力はコンサルティングにとどまらず、ソフトウェア職人技とクリーンコーディングの実践に関するいくつかの影響力のある書籍を著している。

Other books by Robert C. Martin

0:00
-0:00
1x
Dan
Andrew
Michelle
Lauren
Select Speed
1.0×
+
200 words per minute
Create a free account to unlock:
Requests: Request new book summaries
Bookmarks: Save your favorite books
History: Revisit books later
Ratings: Rate books & see your ratings
Try Full Access for 7 Days
Listen, bookmark, and more
Compare Features Free Pro
📖 Read Summaries
All summaries are free to read in 40 languages
🎧 Listen to Summaries
Listen to unlimited summaries in 40 languages
❤️ Unlimited Bookmarks
Free users are limited to 10
📜 Unlimited History
Free users are limited to 10
Risk-Free Timeline
Today: Get Instant Access
Listen to full summaries of 73,530 books. That's 12,000+ hours of audio!
Day 4: Trial Reminder
We'll send you a notification that your trial is ending soon.
Day 7: Your subscription begins
You'll be charged on Feb 28,
cancel anytime before.
Consume 2.8x More Books
2.8x more books Listening Reading
Our users love us
50,000+ readers
"...I can 10x the number of books I can read..."
"...exceptionally accurate, engaging, and beautifully presented..."
"...better than any amazon review when I'm making a book-buying decision..."
Save 62%
Yearly
$119.88 $44.99/year
$3.75/mo
Monthly
$9.99/mo
Try Free & Unlock
7 days free, then $44.99/year. Cancel anytime.
Settings
Appearance
Black Friday Sale 🎉
$20 off Lifetime Access
$79.99 $59.99
Upgrade Now →