A good software architecture should keep the cost of development low over the complete lifetime of an application.
This book discusses how the Hexagonal Architecture style tries to fulfill this goal and translates the concepts into actual code to provide inspiration for software developers.
Author(s): Tom Hombergs
Series: 1
Publisher: Leanpub
Year: 2019
Language: English
Commentary: LaTeX with hyperref package
Pages: 108
Table of Contents
Preface
What Is the Goal of This Book?
Who Should Read This Book?
The Example Application
A Note on Code Examples
Feedback
1. What’s Wrong With Layers?
It Promotes Database-Driven Design
It’s Prone to Shortcuts
It Grows Hard to Test
It Hides the Use Cases
It Makes Parallel Work Difficult
How Does This Help Me Build Maintainable Software?
2. Inverting Dependencies
The Single Responsibility Principle
A Tale about Side Effects
The Dependency Inversion Principle
Clean Architecture
Hexagonal Architecture
How Does This Help Me Build Maintainable Software?
3. Organizing Code
Organizing By Layer
Organizing By Feature
An Architecturally Expressive Package Structure
The Role of Dependency Injection
How Does This Help Me Build Maintainable Software?
4. Implementing a Use Case
Implementing the Domain Model
A Use Case in a Nutshell
Validating Input
The Power of Constructors
Different Input Models for Different Use Cases
Validating Business Rules
Rich vs. Anemic Domain Model
Different Output Models for Different Use Cases
What About Read-Only Use Cases?
How Does This Help Me Build Maintainable Software?
5. Implementing a Web Adapter
Dependency Inversion
Responsibilities of a Web Adapter
Slicing Controllers
How Does This Help Me Build Maintainable Software?
6. Implementing a Persistence Adapter
Dependency Inversion
Responsibilities of a Persistence Adapter
Slicing Port Interfaces
Slicing Persistence Adapters
Example with Spring Data JPA
What about Database Transactions?
How Does This Help Me Build Maintainable Software?
7. Testing Architecture Elements
The Test Pyramid
Testing a Domain Entity with Unit Tests
Testing a Use Case with Unit Tests
Testing a Web Adapter with Integration Tests
Testing a Persistence Adapter with Integration Tests
Testing Main Paths with System Tests
How Much Testing is Enough?
How Does This Help Me Build Maintainable Software?
8. Mapping Between Boundaries
The “No Mapping” Strategy
The “Two-Way” Mapping Strategy
The “Full” Mapping Strategy
The “One-Way” Mapping Strategy
When to use which Mapping Strategy?
How Does This Help Me Build Maintainable Software?
9. Assembling the Application
Why Even Care About Assembly?
Assembling via Plain Code
Assembling via Spring’s Classpath Scanning
Assembling via Spring’s Java Config
How Does This Help Me Build Maintainable Software?
10. Enforcing Architecture Boundaries
Boundaries and Dependencies
Visibility Modifiers
Post-Compile Checks
Build Artifacts
How Does This Help Me Build Maintainable Software?
11. Taking Shortcuts Consciously
Why Shortcuts Are Like Broken Windows
The Responsibility of Starting Clean
Sharing Models between Use Cases
Using Domain Entities as Input or Output Model
Skipping Incoming Ports
Skipping Application Services
How Does This Help Me Build Maintainable Software?
12. Deciding on an Architecture Style
The Domain is King
Experience is Queen
It Depends
Changelog
Notes