logo Mon, 23 Dec 2024 09:26:54 GMT

Clean Architecture


Synopsis


Building upon the success of best-sellers The Clean Coder and Clean Code, legendary software craftsman Robert C. "Uncle Bob" Martin shows how to bring greater professionalism and discipline to application architecture and design.

 

As with his other books, Martin's Clean Architecture doesn't merely present multiple choices and options, and say "use your best judgment": it tells you what choices to make, and why those choices are critical to your success. Martin offers direct, no-nonsense answers to key architecture and design questions like:

  • What are the best high level structures for different kinds of applications, including web, database, thick-client, console, and embedded apps?
  • What are the core principles of software architecture?
  • What is the role of the architect, and what is he/she really trying to achieve?
  • What are the core principles of software design?
  • How do designs and architectures go wrong, and what can you do about it?
  • What are the disciplines and practices of professional architects and designers?

Clean Architecture is essential reading for every software architect, systems analyst, system designer, and software manager -- and for any programmer who aspires to these roles or is impacted by their work.

Robert C. Martin

Summary

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.

Assassin's Creed Atlas

Assassin's Creed Atlas