Tom Hombergs
@TomHombergs
Clean Architecture with Spring
Slide 2
Slide 2 text
No content
Slide 3
Slide 3 text
Layers
Slide 4
Slide 4 text
Why bother with
Architecture?
Slide 5
Slide 5 text
Architecture Goals
Slide 6
Slide 6 text
Architecture Goals
Slide 7
Slide 7 text
The Ultimate Goal of Architecture
The goal of software
architecture is to minimize
the lifetime cost of the
software
Slide 8
Slide 8 text
So ...
What‘s Wrong
With Layers?
Slide 9
Slide 9 text
Disclaimer
Layers are a solid
architecture pattern!
But without additional
restrictions they are prone to
design flaws
Slide 10
Slide 10 text
Database-Driven Design
Slide 11
Slide 11 text
Blurred Boundaries
Slide 12
Slide 12 text
Hard-to-test Shortcuts
Slide 13
Slide 13 text
Hidden Functionality
Slide 14
Slide 14 text
Do Circles
Instead!
Slide 15
Slide 15 text
SOLID Principles
S
O
L
I
D
Single Responsibility Principle
Open-Closed Principle
Liskov Substitution Principle
Interface Segregation Principle
Dependency Inversion Principle
Slide 16
Slide 16 text
Dependency Inversion Principle
SOLID Principles
S
O
L
I
D
Single Responsibility Principle
Open-Closed Principle
Liskov Substitution Principle
Interface Segregation Principle
Slide 17
Slide 17 text
Dependency Inversion Principle
Slide 18
Slide 18 text
Dependency Inversion Principle
We can choose the direction of
any code dependency*
* As long as we have control over the code
Slide 19
Slide 19 text
Clean Architecture (Robert C. Martin)
Slide 20
Slide 20 text
Single Responsibility Principle
Dependency Inversion Principle
SOLID Principles
S
O
L
I
D
Open-Closed Principle
Liskov Substitution Principle
Interface Segregation Principle
Slide 21
Slide 21 text
Single Responsibility Principle
Slide 22
Slide 22 text
Single Responsibility Principle
A module* should have only
one reason to change
* Read: class, package, component, architecture element, software entity, …
Slide 23
Slide 23 text
Single Responsibility Principle – Macro Level
Slide 24
Slide 24 text
Single Responsibility Principle – Macro Level
Slide 25
Slide 25 text
Domain-Driven Design
Only a
Domain-Centric Architecture
allows
Domain-Driven Design
Use Cases with a Single Responsibility in a Hexagonal Architecture
Slide 32
Slide 32 text
Quiz: What does this Application do?
Slide 33
Slide 33 text
Quiz: What does this Application do?
Slide 34
Slide 34 text
Let‘s Get Our
Hands Dirty!
Code Example: https://github.com/thombergs/clean-architecture-example
Slide 35
Slide 35 text
Implementing a Use Case
Code Example: https://github.com/thombergs/clean-architecture-example
Slide 36
Slide 36 text
Implementing a Persistence Adapter with Spring Boot
Code Example: https://github.com/thombergs/clean-architecture-example
Slide 37
Slide 37 text
Implementing a Web Adapter with Spring Boot
Code Example: https://github.com/thombergs/clean-architecture-example
Slide 38
Slide 38 text
Spring & Clean Architecture
Spring doesn't care about which
architecture we're implementing
Spring is easily held at arm's length
Spring helps to test isolated parts of our
architecture
Slide 39
Slide 39 text
Mapping
Strategies
Slide 40
Slide 40 text
Mapping Strategies – Two Way Mapping
Slide 41
Slide 41 text
Mapping Strategies – No Mapping
Slide 42
Slide 42 text
Mapping Strategies – Full Mapping (Command Pattern per Use Case)
Slide 43
Slide 43 text
Mapping Strategies – Mix & Match!
Slide 44
Slide 44 text
Enforcing the
Architecture
Slide 45
Slide 45 text
Enforcing the Architecture - Separate Build Artifacts