Get Your Hands Dirty on Clean Architecture

Book description

Gain insights into how hexagonal architecture can help you keep the cost of development low throughout an application’s lifespan Purchase of the print or Kindle book includes a free PDF eBook

Key Features

  • Explore ways to make your software flexible, extensible, and adaptable
  • Learn new concepts that you can easily blend with your software development style
  • Develop the mindset for making conscious architectural decisions

Book Description

Building for maintainability is key to keeping development costs low and processes easy. The second edition of Get Your Hands Dirty on Clean Architecture is here to equip you with the essential skills and knowledge to build maintainable software.

With this comprehensive guide, you’ll explore the drawbacks of conventional layered architecture and the advantages of domain-centric styles such as Robert C. Martin's Clean Architecture and Alistair Cockburn's Hexagonal Architecture. Then, you’ll dive into hands-on explanations on how to convert hexagonal architecture into actual code. You'll learn in detail about different mapping strategies between the layers of hexagonal architecture and discover how to assemble the architectural elements into an application. Additionally, you’ll understand how to enforce architecture boundaries, which shortcuts produce what types of technical debt, and how, sometimes, it is a good idea to willingly take on those debts.

By the end of this second edition, you'll be armed with a deep understanding of the hexagonal architecture style and be ready to create maintainable web applications that save money and time.

What you will learn

  • Identify potential shortcomings of using a layered architecture
  • Apply varied methods to enforce architectural boundaries
  • Discover how potential shortcuts can affect the software architecture
  • Produce arguments for using different styles of architecture
  • Structure your code according to the architecture
  • Run various tests to check each element of the architecture

Who this book is for

This book is for new as well as seasoned developers seeking to learn and deepen their understanding of hexagonal architecture. Some experience with web development is necessary. The code examples are in Java, but if you are proficient in reading object-oriented code, you’ll understand the examples seamlessly. Instances of detailed Java and framework explanations are fewer, but thorough.

Table of contents

  1. Preface
    1. About the Book
      1. About the Author
      2. Learning Objectives
      3. Audience
      4. Approach
      5. Conventions
      6. Feedback
  2. Chapter 1
  3. What's Wrong with Layers?
    1. It Promotes Database-Driven Design
    2. It's Prone to Shortcuts
    3. It Grows Hard to Test
    4. It Hides the Use Cases
    5. It Makes Parallel Work Difficult
    6. How Does This Help Me Build Maintainable Software?
  4. Chapter 2
  5. Inverting Dependencies
    1. The Single Responsibility Principle
    2. A Tale about Side Effects
    3. The Dependency Inversion Principle
    4. Clean Architecture
    5. Hexagonal Architecture
    6. How Does This Help Me Build Maintainable Software?
  6. Chapter 3
  7. Organizing Code
    1. Organizing by Layer
    2. Organizing by Feature
    3. An Architecturally Expressive Package Structure
    4. The Role of Dependency Injection
    5. How Does This Help Me Build Maintainable Software?
  8. Chapter 4
  9. Implementing a Use Case
    1. Implementing the Domain Model
    2. A Use Case in a Nutshell
    3. Validating Input
    4. The Power of Constructors
    5. Different Input Models for Different Use Cases
    6. Validating Business Rules
    7. Rich versus Anemic Domain Model
    8. Different Output Models for Different Use Cases
    9. What about Read-Only Use Cases?
    10. How Does This Help Me Build Maintainable Software?
  10. Chapter 5
  11. Implementing a Web Adapter
    1. Dependency Inversion
    2. Responsibilities of a Web Adapter
    3. Slicing Controllers
    4. How Does This Help Me Build Maintainable Software?
  12. Chapter 6
  13. Implementing a Persistence Adapter
    1. Dependency Inversion
    2. The Responsibilities of a Persistence Adapter
    3. Slicing Port Interfaces
    4. Slicing Persistence Adapters
    5. Example with Spring Data JPA
    6. What about Database Transactions?
    7. How Does This Help Me Build Maintainable Software?
  14. Chapter 7
  15. Testing Architecture Elements
    1. The Test Pyramid
    2. Testing a Domain Entity with Unit Tests
    3. Testing a Use Case with Unit Tests
    4. Testing a Web Adapter with Integration Tests
    5. Testing a Persistence Adapter with Integration Tests
    6. Testing Main Paths with System Tests
    7. How Much Testing is Enough?
    8. How Does This Help Me Build Maintainable Software?
  16. Chapter 8
  17. Mapping Between Boundaries
    1. The "No Mapping" Strategy
    2. The "Two-Way" Mapping Strategy
    3. The "Full" Mapping Strategy
    4. The "One-Way" Mapping Strategy
    5. When to Use Which Mapping Strategy?
    6. How Does This Help Me Build Maintainable Software?
  18. Chapter 9
  19. Assembling the Application
    1. Why Even Care about Assembly?
    2. Assembling via Plain Code
    3. Assembling via Spring's Classpath Scanning
    4. Assembling via Spring's Java Config
    5. How Does This Help Me Build Maintainable Software?
  20. Chapter 10
  21. Enforcing Architecture Boundaries
    1. Boundaries and Dependencies
    2. Visibility Modifiers
    3. Post-Compile Checks
    4. Build Artifacts
    5. How Does This Help Me Build Maintainable Software?
  22. Chapter 11
  23. Taking Shortcuts Consciously
    1. Why Shortcuts Are Like Broken Windows
    2. The Responsibility of Starting Clean
    3. Sharing Models between Use Cases
    4. Using Domain Entities as Input or Output Models
    5. Skipping Incoming Ports
    6. Skipping Application Services
    7. How Does This Help Me Build Maintainable Software?
  24. Chapter 12
  25. Deciding on an Architecture Style
    1. The Domain is King
    2. Experience is Queen
    3. It Depends

Product information

  • Title: Get Your Hands Dirty on Clean Architecture
  • Author(s): Tom Hombergs
  • Release date: September 2019
  • Publisher(s): Packt Publishing
  • ISBN: 9781839211966