Chapter 1: Introduction
This chapter introduces the concept of Clean Architecture, which advocates for separating business logic from infrastructure and frameworks. It emphasizes the importance of building robust and maintainable software systems that are independent of underlying technologies.
Example: Consider a web application that performs financial calculations. The business logic should be contained in a separate module, independent of the web framework (e.g., Spring MVC) and database (e.g., MySQL).
Chapter 2: The Dependency Rule
This chapter establishes the "Dependency Rule," which states that dependencies should flow inward, from high-level modules to low-level modules. High-level modules should not depend on low-level implementation details.
Example: The business logic module should not directly use the database connection. Instead, it should interact with a data access layer that hides database implementation details.
Chapter 3: Layering
This chapter describes how to organize code into layers based on the Dependency Rule. It proposes a layered architecture with three main layers:
* Domain Layer: Contains the business logic and domain objects.
* Application Layer: Mediates between the domain layer and infrastructure.
* Infrastructure Layer: Provides services such as database access, logging, and networking.
Example: The web application's domain layer would contain classes like "Account" and "Transaction." The application layer would handle HTTP requests and responses, while the infrastructure layer would interact with the database.
Chapter 4: Adapters
This chapter introduces the concept of adapters, which are responsible for translating data and interfaces between layers. Adapters enable communication between layers without violating the Dependency Rule.
Example: A "Web API Adapter" could convert JSON HTTP request data into domain objects, and vice versa.
Chapter 5: Controllers
This chapter discusses the role of controllers in the application layer. Controllers are responsible for handling user interactions and orchestrating business logic. They should be simple and focused on coordinating the flow of data between the user interface and the domain layer.
Example: A "Transaction Controller" would receive a HTTP request to create a transaction, convert request data into a domain object, and call the domain layer to create the transaction.
Chapter 6: Entity-Boundary-Controller
This chapter introduces the Entity-Boundary-Controller (EBC) pattern, which provides a structured approach to designing controllers. An EBC controller consists of:
* Entity: Represents the domain object being manipulated.
* Boundary: Defines the interface between the controller and the entity.
* Controller: Orchestrates the flow of data and business logic.
Example: A "Transaction EBC Controller" would have a "TransactionBoundary" interface that defines methods for creating and modifying transactions.
Chapter 7: Use Cases
This chapter describes how to organize business logic into use cases. A use case represents a specific business functionality that can be performed by the system. It should be independent of infrastructure and implementation details.
Example: The "Create Transaction" use case would encapsulate the business logic for creating a new transaction, including validations and interactions with other domain objects.
Chapter 8: Unit Testing
This chapter emphasizes the importance of unit testing Clean Architecture applications. Tests should focus on testing individual layers and dependencies in isolation. It discusses techniques for mocking and isolating components to ensure code quality and maintainability.
Example: A unit test for the "Transaction Controller" could verify that it correctly calls the "Create Transaction" use case.
Chapter 9: Conclusion
This chapter summarizes the principles and benefits of Clean Architecture. It highlights the importance of aligning software design with business needs and the value of building robust and maintainable systems that can withstand changing technologies and business requirements.